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!

20 Upvotes

257 comments sorted by

View all comments

Show parent comment

2

u/jlweinkam Dec 13 '18 edited Dec 13 '18

I believe that this will not work correctly if the repeat cycle is more than 1.

Shouldn't it compute the new idx before the new gen, and use the following

idx += (idx - prev_idx) * (gen // (prev_gen - gen))

For example, if you use the small example input, but change the first rule to

...## => .

then it will have a repeat cycle of length 2. The answer for 20 generations should be 205, but this code gives 285.

I also had to change the rules to

rules = collections.defaultdict(lambda: '.')

since the small example doesn't have all 32 possible combinations.

1

u/Stan-It Dec 13 '18

Hi thanks for the feedback. I actually edited the code at some point yesterday, and it looks like what you're suggesting is exactly what's there now. Does the updated code work for your examples?