My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add 2025/03

+28
+28
2025/day03.py
··· 1 + import fileinput 2 + from functools import cache 3 + 4 + 5 + @cache 6 + def dp(s, n): 7 + """Dynamic program to get the max joltage of a string.""" 8 + if n == 1: 9 + return max(s) 10 + 11 + poss = [] 12 + for i in range(len(s) - n + 1): 13 + poss.append(s[i] + dp(s[i+1:], n - 1)) 14 + 15 + return max(poss) 16 + 17 + 18 + PART_1 = 0 19 + PART_2 = 0 20 + 21 + for bank in fileinput.input(): 22 + bank = bank.strip() 23 + PART_1 += int(dp(bank, 2)) 24 + PART_2 += int(dp(bank, 12)) 25 + 26 + print("Part 1:", PART_1) 27 + print("Part 2:", PART_2) 28 +