commit bdcdf6f58271008c590ac9157e73c901280d092a parent 3e40017c5e856fbbc33bbdd53a9a8e1d2b02abd8 Author: Sebastiano Tronto <sebastiano@tronto.net> Date: Mon, 1 Dec 2025 06:54:43 +0100 Day 1 I am stupid and I don't know why Diffstat:
| M | 2025/01/a.py | | | 8 | +++++++- |
| A | 2025/01/b.py | | | 19 | +++++++++++++++++++ |
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/2025/01/a.py b/2025/01/a.py @@ -1,6 +1,12 @@ import fileinput +p = 50 +c = 0 with fileinput.input() as lines: for line in lines: - ... + s = 1 if line[0] == "R" else -1 + p = (p + s * int(line[1:])) % 100 + if p == 0: + c += 1 +print(c) diff --git a/2025/01/b.py b/2025/01/b.py @@ -0,0 +1,19 @@ +import fileinput + +p = 50 +c = 0 +with fileinput.input() as lines: + for line in lines: + oldp = p + s = 1 if line[0] == "R" else -1 + p += s * int(line[1:]) + if p >= 100: + d = p // 100 + c += d + p -= d * 100 + elif p <= 0: + d = -p // 100 + 1 + c += d if oldp != 0 else d-1 + p = (p + d * 100) % 100 + +print(c)