Note: This topic is to talk about Day 18 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.
Note: This topic is to talk about Day 18 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.
Here is my take. I solved part 2 by detecting cycles. It’s not super fast, finishes in about 7 sec. There’s some room for optimizing, but I didn’t want to uglify the code
I had fun with streams in this one. I also implemented a cycle finding algorithm.
Running the cycle finding algorithm on the infinite stream turned out to be too slow, though, so I cheated a little by pulling out 2000 values to a finite enumerable. That is probably long enough to work for most people’s data sets. The cycle in my data starts at 452 minutes.
It finishes in about 12 minutes.
@sasajuric I liked the elegant way in which you cached the data from the infinite stream and detected the cycle at the same time.
Update: Forgot the link.
I caught up just in time to go on vacation: here’s my solution to Day 18: