r/adventofcode • • 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!

Click here for rules

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!

18 Upvotes

257 comments sorted by

View all comments

Show parent comment

1

u/dudeatwork Dec 13 '18

I didn't hit on the linear pattern

I don't quite follow, your code does "exit" once it sees the same sum 100 times in a row.

// skip ahead if so
if (sameCount > 100) {
    let remaining = (numGenerations - gen);
    sum += delta * remaining;
    break;
}

Are you saying you initially didn't clue in on that, and so tried making the whole program faster so you could really try and run through the fifty billion iterations, but then after your optimizations figured out the "stabilization" trick?

Nice use of the the double-ended-queue package! Didn't know about that one, would have made this one a bit easier for me if I thought to search NPM first. :)

1

u/myndzi Dec 13 '18

Yes, I didn't initially clue in on that, due to my unfamiliarity with cellular automata. So I tried to make the whole thing fast enough, not quite knowing if it would work ;) This solution is the result of that attempt, plus the actual inclusion of a convergence check which _actually_ got the job done, but I thought there was some interesting stuff worth sharing

double-ended-queue is by the same author as Bluebird, so I have some confidence in its performance optimization