diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-03 06:22:35 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-03 06:22:35 +0100 |
| commit | 39e9d936f52c7626884d1ca4c5262b117b0dc85c (patch) | |
| tree | 02bd60816e10f0f9253d89d10755388c03eaa01c /2025/03/b.py | |
| parent | d662d817052767047807f8f1d5643608b9943fa0 (diff) | |
| download | aoc-39e9d936f52c7626884d1ca4c5262b117b0dc85c.tar.gz aoc-39e9d936f52c7626884d1ca4c5262b117b0dc85c.zip | |
Day 3 2025
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)) | ||
