Advent of code d3
Only showing the phase 2 solution here. Becuase it is so far removed from the phase 1 solution, that I'd have to re-implement phase 1.
import traceback
result = 0
try:
with open("day3-input.txt", "r") as f:
for line in f.readlines():
line = line.strip()
if not line:
continue
start = 0
found = []
for i in range(12):
rem = 12 - (i + 1)
limit = len(line) - rem
d = line[start]
index = start
for j in range(start, limit):
if int(line[j]) > int(d):
d = line[j]
index = j
if d == "9":
break
found.append(d)
start = index + 1
result += int("".join(found))
except Exception as e:
traceback.print_exc()
print(result)