day 3 part 1 solved!

bram-benchmarks
Brechtje van Gessel 2025-12-03 23:33:48 +01:00
parent a92e05928f
commit 561edcc1a5
1 changed files with 19 additions and 0 deletions

19
brechtje/3/3-1.py Normal file
View File

@ -0,0 +1,19 @@
input = open("input.txt").read().splitlines()
def find_biggest_num(line, start, is_first_num):
num = -1
max_num = 9
while True:
num = line.find(str(max_num), start)
if num == -1 or (is_first_num and num == len(line) - 1):
max_num -= 1
else:
return num
answer = 0
for line in input:
first_num = find_biggest_num(line, 0, True)
second_num = find_biggest_num(line, first_num + 1, False)
answer += int(line[first_num] + line[second_num])
print(answer)