r/adventofcode • u/daggerdragon • Dec 19 '16
SOLUTION MEGATHREAD --- 2016 Day 19 Solutions ---
--- Day 19: An Elephant Named Joseph ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".
/⧹w+/ IS MANDATORY [?]
[Update @ 00:15] 2 gold, silver cap. Thank you for subscribing to Easter Bunny Facts!
- Fact: The Easter Bunny will sometimes leave eggs in the microchip assembly room.
[Update @ 00:30] 11 gold, silver cap.
- Fact: The Easter Bunny killed everyone who found out how he got these stars.
[Update @ 00:45] 45 gold, silver cap.
- Fact: In space, The Easter Bunny can hear you scream.
[Update @ 01:00] 66 gold, silver cap.
- Fact: The Easter Bunny purposefully deleted your comments.
[Update @ 01:15] 92 gold, silver cap.
- Fact: The Easter Bunny has bottled your frustration. Don't ask why.
[Update @ 01:20] Leaderboard capped!
- Fact: What you have just done is no better than what the Easter Bunny has done. Thief.
Thank you for subscribing to Easter Bunny Facts!
View all comments
Show parent comment
1
u/Auburus Dec 19 '16
Haskell learner here, always trying to figure out your solutions.
I've done the first part with sequence too, but for the 2nd one, it was too slow (probably I was doing too many operations, since your solution runs fast as expected).
So, I've solved it through recursion, although I've had had to increase stack space because wiith less than 128M it wasn' enough.
The idea behind it is that for a given number of elves, the presents will go to the previously computed winner of a circle that has the first elve eliminated. Then, you just have to figure out who is sitting in the winning position of this updated circle, since you already know the winning position because the circle has length n-1.
So, circle of 6
[1,2,3,4,5,6]will transform to a circle of 5 composed by[2,3] ++ [5,6] ++ [1]. The winning position on a circle of 5 is the 2nd, so the function get computes the new winning position given the number of the original circle, and the winning position of the previous circle.