From bdcdf6f58271008c590ac9157e73c901280d092a Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 1 Dec 2025 06:54:43 +0100 Subject: Day 1 I am stupid and I don't know why --- 2025/01/a.py | 8 +++++++- 2025/01/b.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 2025/01/b.py (limited to '2025/01') diff --git a/2025/01/a.py b/2025/01/a.py index 5fdb11b..114acb4 100644 --- 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 new file mode 100644 index 0000000..ea32dc7 --- /dev/null +++ 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) -- cgit v1.3