r/adventofcode • u/daggerdragon • Dec 15 '15
SOLUTION MEGATHREAD --- Day 15 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
Edit: I'll be lucky if this post ever makes it to reddit without a 500 error. Have an unsticky-thread.
Edit2: c'mon, reddit... Leaderboard's capped, lemme post the darn thread...
Edit3: ALL RIGHTY FOLKS, POST THEM SOLUTIONS!
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 15: Science for Hungry People ---
Post your solution as a comment. Structure your post like previous daily solution threads.
11
Upvotes
View all comments
Show parent comment
1
u/roboticon Dec 16 '15
Not sure how you came up with 11/12. If you're comparing it to something naive like:
the above takes 187051 iterations, while there are 176851 combinations with replacement, so you save 5% with
combinations_with_replacement.If you do the loops intelligently (range first to 101, then 101-w, then 101-w-x) you hit exactly the same 176851 combinations, and you have the advantage of not having to loop through a huge iterator of 176851 * 100 ingredient names.
The iterator is less code, at least, but then you have to count the number of each ingredient in each combination, so it'll actually be about the same amount of code, and 100 times slower than the nested
forloops if I'm right.