diff options
author | mhsn <mail@mhsn.net> | 2024-12-10 20:42:35 +0000 |
---|---|---|
committer | mhsn <mail@mhsn.net> | 2024-12-10 20:42:35 +0000 |
commit | 84723ce9e2457fa8aa0bb2790a8c13242e88ec7e (patch) | |
tree | f6233bdcd22b9144d0bab2b747add858a6f4d860 | |
parent | 7bae45c3d7cb01774093a513d149ff567265a6a7 (diff) | |
download | aoc-84723ce9e2457fa8aa0bb2790a8c13242e88ec7e.tar.gz aoc-84723ce9e2457fa8aa0bb2790a8c13242e88ec7e.zip |
2024-05 python cleanup
-rw-r--r-- | 2024/05/python/main.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/2024/05/python/main.py b/2024/05/python/main.py index c365cfe..e3a10e2 100644 --- a/2024/05/python/main.py +++ b/2024/05/python/main.py @@ -1,27 +1,25 @@ from fileinput import input from functools import cmp_to_key +from itertools import takewhile -silver = 0 -gold = 0 - -lines = [line.strip() for line in input()] -split = lines.index("") - -ordering, updates = lines[:split], lines[split + 1 :] +inp = map(str.strip, input()) +ordering = set(takewhile(bool, inp)) +us = list(inp) def cmp(x, y): - if f"{y}|{x}" in ordering: - return 1 - return -1 + return (f"{y}|{x}" in ordering) * 2 - 1 # hehe -for update in updates: - raw = update.split(",") - fixed = list(sorted(raw, key=cmp_to_key(cmp))) +silver = 0 +gold = 0 + +for u in us: + pre = u.split(",") + post = list(sorted(pre, key=cmp_to_key(cmp))) - mid = int(fixed[len(fixed) // 2]) - if fixed == raw: + mid = int(post[len(post) // 2]) + if pre == post: silver += mid else: gold += mid |