From 81741232af8921af1c9f4cbd4174679ed95ec763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Sun, 1 Dec 2024 06:35:18 +0100 Subject: [PATCH] Solve 2024:1 p1-2 "Historian Hysteria" Realized afterwards I got the ints() helper, so original code before cleanup splitted the input and mapped all words with int(). valuable seconds lost there. Also, collections.Counter() was used initially since I was too tired to remember count() method in lists. Line 8 took the longest time to figure out. A typo took 1-3 minutes to find for part 2. Form: Sleep deprived, felt slow. --- 2024-python/output/day_01.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 2024-python/output/day_01.py diff --git a/2024-python/output/day_01.py b/2024-python/output/day_01.py new file mode 100644 index 0000000..104aba3 --- /dev/null +++ b/2024-python/output/day_01.py @@ -0,0 +1,20 @@ +from output import ints + + +def solve(puzzle_input): + left, right = [sorted(col) for col in zip(*map(ints, puzzle_input.splitlines()))] + + p1 = sum(abs(l - r) for l, r in zip(left, right)) + p2 = sum(k * right.count(k) for k in left) + + return p1, p2 + + +if __name__ == "__main__": + with open("./input/01.txt", "r") as f: + puzzle_input = f.read().strip() + + p1, p2 = solve(puzzle_input) + + print(p1) + print(p2)