diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-03 13:06:51 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-03 13:07:18 +0100 |
| commit | 2329b38f531bc93de6e682e1af9e995072c6175c (patch) | |
| tree | 26e1ef27514b8bafd86e05ac9a123b1266f8ab96 /2025 | |
| parent | 1dc404e7ee276f6a5798ec93d5ae47e08d180432 (diff) | |
| download | aoc-2329b38f531bc93de6e682e1af9e995072c6175c.tar.gz aoc-2329b38f531bc93de6e682e1af9e995072c6175c.zip | |
3b alternative solution suggested by Chiara
Diffstat (limited to '2025')
| -rw-r--r-- | 2025/03/b-alt.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/2025/03/b-alt.py b/2025/03/b-alt.py new file mode 100644 index 0000000..43e2695 --- /dev/null +++ b/2025/03/b-alt.py | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | import fileinput | ||
| 2 | |||
| 3 | def joltage(line, n): | ||
| 4 | if n == 0: | ||
| 5 | return 0 | ||
| 6 | |||
| 7 | x = max(line[:len(line) - (n-1)]) | ||
| 8 | return x*10**(n-1) + joltage(line[line.index(x)+1:], n-1) | ||
| 9 | |||
| 10 | with fileinput.input() as lines: | ||
| 11 | print(sum(joltage([int(x) for x in line[:-1]], 12) for line in lines)) | ||
