diff options
Diffstat (limited to '2025/03/b.py')
| -rw-r--r-- | 2025/03/b.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/2025/03/b.py b/2025/03/b.py new file mode 100644 index 0000000..4c74ae6 --- /dev/null +++ b/2025/03/b.py | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | import fileinput | ||
| 2 | from functools import cache | ||
| 3 | |||
| 4 | neginf = -1e13 | ||
| 5 | |||
| 6 | @cache | ||
| 7 | def joltage(line, n): | ||
| 8 | if n == 0: | ||
| 9 | return 0 | ||
| 10 | if n > len(line)-1: | ||
| 11 | return neginf | ||
| 12 | j = 0 | ||
| 13 | for i in range(len(line)-1): | ||
| 14 | j = max(j, int(line[i])*10**(n-1)+joltage(line[i+1:],n-1)) | ||
| 15 | return j | ||
| 16 | |||
| 17 | with fileinput.input() as lines: | ||
| 18 | print(sum(joltage(line, 12) for line in lines)) | ||
