advent-of-code/2025-python/output/day_03.py

32 lines
640 B
Python
Raw Normal View History

def solve(data):
p1 = 0
p2 = 0
for line in data.splitlines():
p1 += _maxj(line, 2)
p2 += _maxj(line, 12)
return p1, p2
def _maxj(line, C):
toexcl = len(line) - C
batt = []
for c in line:
while toexcl and batt and batt[-1] < c:
toexcl -= 1
batt.pop()
batt.append(c)
return sum(10**x * int(y) for x, y in zip(range(C - 1, -1, -1), batt))
if __name__ == "__main__":
with open("./input/03.txt", "r") as f:
inp = f.read().strip()
p1, p2 = solve(inp)
print(p1)
print(p2)
assert p1 == 17430
assert p2 == 171975854269367