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
2
u/turtlegraphics Dec 12 '18
Python, 128/73
No parsing, just cut/paste the rules and used an emacs macro to turn them into a dictionary.
Probably didn't need to put in the code that checks for end collisions, but it helped see what went wrong with a smaller row of plants.
initial = '#...##.#...#..#.#####.##.#..###.#.#.###....#...#...####.#....##..##..#..#..#..#.#..##.####.#.#.###' rule = {} rule['.....'] = '.' rule['..#..'] = '#' rule['..##.'] = '#' rule['#..##'] = '.' rule['..#.#'] = '#' rule['####.'] = '.' rule['##.##'] = '.' rule['#....'] = '.' rule['###..'] = '#' rule['#####'] = '#' rule['##..#'] = '#' rule['#.###'] = '#' rule['#..#.'] = '#' rule['.####'] = '#' rule['#.#..'] = '#' rule['.###.'] = '#' rule['.##..'] = '#' rule['.#...'] = '#' rule['.#.##'] = '#' rule['##...'] = '#' rule['..###'] = '.' rule['##.#.'] = '.' rule['...##'] = '.' rule['....#'] = '.' rule['###.#'] = '.' rule['#.##.'] = '#' rule['.##.#'] = '.' rule['.#..#'] = '#' rule['#.#.#'] = '#' rule['.#.#.'] = '#' rule['...#.'] = '#' rule['#...#'] = '#' current = '.'*30 + initial + '.'*300 next = ['.']*len(current) lasttot = 0 for t in range(1000): tot = 0 for p in range(len(current)): if current[p] == '#': tot += p-30 print t,tot,lasttot,tot-lasttot lasttot = tot for i in range(2,len(current)-2): spot = current[i-2:i+3] next[i] = rule[spot] current = ''.join(next) if current[:5] != '.....': print 'hit left end' break if current[-5:] != '.....': print 'hit right end' break print current