This commit is contained in:
2026-05-11 07:14:24 +01:00
parent cc20656214
commit 40a85a3c10
5 changed files with 122 additions and 4 deletions
+51 -3
View File
@@ -1,7 +1,55 @@
testing = True testing = False
if not testing: if not testing:
with open(r"2025/03/input.txt", "r") as file: with open(r"2025/03/input.txt", "r") as file:
input = file.read() input = file.read()
else: else:
input = ''' 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)
+56
View File
@@ -0,0 +1,56 @@
testing = True
if not testing:
with open(r"2025/03/input.txt", "r") as file:
input = file.read()
else:
input = '''987654321111111
811111111111119
234234234234278
818181911112111'''
testing_answer = 3121910778619
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-12:
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)
+7
View File
@@ -0,0 +1,7 @@
testing = True
if not testing:
with open(r"2025/04/input.txt", "r") as file:
input = file.read()
else:
input = '''
'''
+7
View File
@@ -0,0 +1,7 @@
testing = True
if not testing:
with open(r"2025/05/input.txt", "r") as file:
input = file.read()
else:
input = '''
'''
+1 -1
View File
@@ -135,4 +135,4 @@ def populate_data(year = current_year, day=current_day):
else: else:
print("Something went wrong. Check the puzzle text.") print("Something went wrong. Check the puzzle text.")
populate_data() populate_data(2025,4)