diff options
| author | mhsn <mail@mhsn.net> | 2025-12-02 19:27:28 +0000 |
|---|---|---|
| committer | mhsn <mail@mhsn.net> | 2025-12-02 19:27:28 +0000 |
| commit | def7ab6f54d52319f394c235aa6664a1a99309cd (patch) | |
| tree | d64e503c3c69e0ed904f8fb632d8b53fb69a3c80 /2025/01 | |
| parent | ffb3260575dc2502faebef09127839b54d7eab44 (diff) | |
| download | aoc-def7ab6f54d52319f394c235aa6664a1a99309cd.tar.gz aoc-def7ab6f54d52319f394c235aa6664a1a99309cd.zip | |
25-01 python p2
Diffstat (limited to '2025/01')
| -rwxr-xr-x | 2025/01/python.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/2025/01/python.py b/2025/01/python.py index 2ba0bbd..d5ff1fa 100755 --- a/2025/01/python.py +++ b/2025/01/python.py @@ -3,12 +3,13 @@ from fileinput import input from itertools import accumulate -lines = [line.strip() for line in input()] -add = lambda p, m: (p + int(m[1:]) * ((m[0] == "R") * 2 - 1)) % 100 +def fn(p: tuple[int, int], rot: str) -> tuple[int, int]: + x = p[0] + int(rot[1:]) * (1 if rot[0] == "R" else -1) + return x % 100, abs(x) // 100 + (p[0] and x <= 0) -silver = sum(p == 0 for p in accumulate(lines, add, initial=50)) -gold = 0 -print("silver:", silver) -print("gold:", gold) +p1, p2 = zip(*list(accumulate(input(), fn, initial=(50, 0)))) + +print(f"silver: {sum(not p for p in p1)}") +print(f"gold: {sum(p2)}") |
