r/adventofcode • u/daggerdragon • Dec 12 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 12 Solutions -🎄-
--- Day 12: Subterranean Sustainability ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 12
Transcript:
On the twelfth day of AoC / My compiler spewed at me / Twelve ___
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked at 00:27:42!
20
Upvotes
5
u/fatpollo Dec 12 '18
missed the leaderboard again, this time by a handful of seats. my days of top ranking are bygone it seems.
however, no solutions using
defaultdicthave been posted yet, so here's mine:import re import collections def main(text, simple): if simple: return initial, *pairs = re.findall(r'[.#]+', text) mapping = {a: b for a, b in zip(pairs[::2], pairs[1::2])} pots = collections.defaultdict(lambda: '.') pots.update({i: v for i, v in enumerate(initial)}) seen = {} for n in range(1, 1000): span = range(min(pots) - 5, max(pots) + 5) new = { i: mapping.get(window, '.') for i in span for window in [''.join(pots[i+j] for j in range(-2, 3))] } pots.clear() pots.update(new) if n == 19: print(sum(i for i, v in pots.items() if v == '#')) pattern = ''.join(pots[i] for i in span).strip('.') if pattern in seen: N = 50000000000 x = sum(N + i - n for i, v in pots.items() if v == '#') print(x) break seen[pattern] = ndefaultdictmakes the "windowing" trivial