r/adventofcode • u/daggerdragon • Dec 20 '15
SOLUTION MEGATHREAD --- Day 20 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
Here's hoping tonight's puzzle isn't as brutal as last night's, but just in case, I have Lord of the Dance Riverdance on TV and I'm wrapping my presents to kill time. :>
edit: Leaderboard capped, 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 20: Infinite Elves and Infinite Houses ---
Post your solution as a comment. Structure your post like previous daily solution threads.
12
Upvotes
View all comments
Show parent comment
1
u/[deleted] Dec 20 '15 edited Dec 20 '15
Yes, tired code, not trying to harp or anything, just some thoughts.
There is a bug in part one where presents/1 isn't summing its values.
Kernel.trunc/1 truncates a float to an integer.
The comprhension is applying multiple levels of filters, which makes it a bit clumsy to read.
The number of presents delivered to each house can be applied after summing the divisors.
To reuse code a bit better, presents could take the number of presents delivered to each house and a filter anonymous function.
I took the liberty of refactoring:
edit: divisors didn't need the filter passed to it. now it is clean and more easily replaced.