testing = False if not testing: with open(r"2025/03/input.txt", "r") as file: input = file.read() else: input = '''987654321111111 811111111111119 234234234234278 818181911112111''' testing_answer = 357 banks = input.split('\n') mem = {} jolts = [] for bank_number, battery_bank in enumerate(banks): # scan the whole bank # find the highest number # store it and remember its position # need to handle if the last digit is the highest as that wont work... bank_length = len(battery_bank) current_high:int = 0 current_high_pos: int for position, battery in enumerate(battery_bank): if position == bank_length-1: continue battery = int(battery) if battery > current_high: current_high = battery current_high_pos = position mem[bank_number] = (current_high, current_high_pos) # print(current_high, current_high_pos) #print(mem) for bank_number, battery_bank in enumerate(banks): current_high:int = 0 current_high_pos: int for position, battery in enumerate(battery_bank): if position <= mem[bank_number][1]: #print('skip') continue battery = int(battery) if battery > current_high: current_high = battery jolts.append(mem[bank_number][0]*10 + current_high) # print(jolts) sum_jolts = 0 for thing in jolts: sum_jolts += thing if testing: print(sum_jolts == testing_answer) print(sum_jolts)