sasajuric
Advent of Code - Day 12
Note: This topic is to talk about Day 12 of the Advent of Code.
For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.
Most Liked
sasajuric
My solution is here.
Part 1 was pretty straightforward. I built a map of rules, and then used a bit of binary pattern matching to move to the next state.
In part 2 it really helped me that I did AoC last year. As soon as I saw it, I knew that there had to be a cycle. I did a quick experiment, and found out that the plants converge to the stable state pretty soon. In that state, the plants relative positioning doesn’t change, but they gradually move in one direction.
I briefly thought about solving this special case, but I wasn’t quite happy with that, because I thought there might exist a more general situation with larger cycles. Therefore, I wrote a more complex recursion which caches pattern transitions, and can handle the cycle of any length.
JEG2
Here’s my solution to Day 12:
I also found the cycle and quit there.
Here’s a video of the creation of this code (good for 14 days):
theshank
sasajuric
That function has multiple clauses (in this case two - in lines 10 and 12 respectively, and it also has a default third argument. In this case, a separate bodyless function clause is needed to declare defaults. This is explained in the def documentation.








