2025-12-03 10:46:19 -06:00

40 lines
863 B
Python

input_file = "input.txt"
banks: list[list[int]] = []
with open(input_file, 'r') as file:
banks = [ [ int(n) for n in line.strip() ] for line in file.readlines() ]
total_joltage = 0
ALLOWED_BATTERY_COUNT = 12
for i, bank in enumerate(banks):
nums: list[int] = []
last_n_index = 0
for battery in reversed(range(ALLOWED_BATTERY_COUNT)):
if battery:
n = max(bank[last_n_index:-battery])
nums.append(n)
last_n_index = bank.index(n, last_n_index) + 1
else:
n = max(bank[last_n_index:])
nums.append(n)
last_n_index = bank.index(n, last_n_index) + 1
# Convert Nums to an Int
joltage = int(''.join([ str(n) for n in nums]))
print(f'Joltage for Bank {i + 1}: {joltage}')
total_joltage += joltage
print(f'Total Joltage: {total_joltage}')