r/adventofcode • u/daggerdragon • Dec 09 '15
SOLUTION MEGATHREAD --- Day 9 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
edit: Leaderboard capped, achievement thread unlocked!
We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
Please and thank you, and much appreciated!
--- Day 9: All in a Single Night ---
Post your solution as a comment. Structure your post like previous daily solution threads.
11
Upvotes
View all comments
Show parent comment
1
u/haljin Dec 09 '15
This gave me a little headache as I tried to come up with a non-recursive (or rather tail-recursive) solution to this problem. Finally came up with this:
Funnily enough, when you switch
NewPaths ++ RestPathsaround like I did at the beginning the code starts executing horribly long (well 20 seconds for such a small dataset is pretty slow). When they are in this order it drops to about 294 ms. I did a quick eprof a found out just how very slow ++ is when you add the long list in front of a small one.Of course in the middle I got an idea for another solution. Spawn a process (in "void" at first) and give him all the possible paths. If there's more than one, he spawns friends and each goes somewhere else. Rinse repeat until there's nowhere to go.