From 0eb961d31c74f62c6d8403647679f3b8dde46798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Wed, 11 Dec 2024 08:23:26 +0100 Subject: [PATCH] Solve 2024:11 p1-2 "Plutonian Pebbles" First part was solved using a list to store stones, since I misinterpreted this paragraph: > No matter how the stones change, their order is > preserved, and they stay on their perfectly > straight line. But since the puzzle question do not require the stones in the correct order, a list (or an OrderedDict) is not required. The pt 1 solution code got killed for eating all RAM, so valuable minutes was lost trying to create a generator instead. It failed. When searching for clues, I ran across multiple people instead utilizing dicts to count occourences. "but what of the order?", I asked, and realized only the counts was relevant. --- 2024-python/output/day_11.py | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 2024-python/output/day_11.py diff --git a/2024-python/output/day_11.py b/2024-python/output/day_11.py new file mode 100644 index 0000000..1441929 --- /dev/null +++ b/2024-python/output/day_11.py @@ -0,0 +1,38 @@ +from collections import defaultdict + +from output import ints + + +def solve(data): + state = defaultdict(int) + for e in ints(data): + state[e] += 1 + for lap in range(75): + if lap == 25: + stones_count_25 = sum(state.values()) + queue = list(map(lambda x: x, state.items())) + for e, delta in queue: + if e == 0: + state[1] += delta + state[0] -= delta + elif len(str(e)) % 2 == 0: + i = len(str(e)) // 2 + l, r = int(str(e)[:i]), int(str(e)[i:]) + state[l] += delta + state[r] += delta + state[e] -= delta + else: + state[e * 2024] += delta + state[e] -= delta + stones_count_75 = sum(state.values()) + return stones_count_25, stones_count_75 + + +if __name__ == "__main__": + with open("./input/11.txt", "r") as f: + inp = f.read().strip() + + p1, p2 = solve(inp) + + print(p1) + print(p2)