a
This commit is contained in:
@@ -1,7 +1,55 @@
|
||||
testing = True
|
||||
testing = False
|
||||
if not testing:
|
||||
with open(r"2025/03/input.txt", "r") as file:
|
||||
input = file.read()
|
||||
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)
|
||||
@@ -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)
|
||||
@@ -0,0 +1,7 @@
|
||||
testing = True
|
||||
if not testing:
|
||||
with open(r"2025/04/input.txt", "r") as file:
|
||||
input = file.read()
|
||||
else:
|
||||
input = '''
|
||||
'''
|
||||
@@ -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
@@ -135,4 +135,4 @@ def populate_data(year = current_year, day=current_day):
|
||||
else:
|
||||
print("Something went wrong. Check the puzzle text.")
|
||||
|
||||
populate_data()
|
||||
populate_data(2025,4)
|
||||
|
||||
Reference in New Issue
Block a user