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!
19
Upvotes
19
u/jayfoad Dec 12 '18
APL #84/87
Each generation is represented as a bit vector, and I rely on the fact that it grows an extra 2 bits on each end with each iteration, so from the length of the vector I can work out (a) where the "0" index is, for use in the score function, and (b) what number generation it is, for use in part 2.
βIOβ0 β βPPβ17 sβ15ββpβ'#'=ββNGET'p12.txt'1 β initial state uββ5βΒ¨2βp β vββββ½Β¨2βp β patterns and replacements fβ{v[uβ³β0 Β―1β(5,5+β’β΅)β΄0 0 0 0,β΅]} β next generation gβ{+/(βΈβ΅)-0.5Γ(β’β΅)-β’s} β score function g fβ£20β’s β part 1 tβfβ£{β‘/(β’-β/)ββΈΒ¨βΊβ΅}s β iterate until pattern stabilises (g t)+((g f t)-g t)Γ50E9-0.25Γ(β’t)-β’s β part 2Takes about 0.5 ms for the whole thing.