commit 2329b38f531bc93de6e682e1af9e995072c6175c parent 1dc404e7ee276f6a5798ec93d5ae47e08d180432 Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Wed, 3 Dec 2025 13:06:51 +0100 3b alternative solution suggested by Chiara Diffstat:
| A | 2025/03/b-alt.py | | | 11 | +++++++++++ |
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/2025/03/b-alt.py b/2025/03/b-alt.py @@ -0,0 +1,11 @@ +import fileinput + +def joltage(line, n): + if n == 0: + return 0 + + x = max(line[:len(line) - (n-1)]) + return x*10**(n-1) + joltage(line[line.index(x)+1:], n-1) + +with fileinput.input() as lines: + print(sum(joltage([int(x) for x in line[:-1]], 12) for line in lines))