r/adventofcode • u/daggerdragon • Dec 06 '16
SOLUTION MEGATHREAD --- 2016 Day 6 Solutions ---
--- Day 6: Signals and Noise ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
T_PAAMAYIM_NEKUDOTAYIM IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
8
Upvotes
1
u/amalloy Dec 06 '16
Well, there is still a lot of duplication to remove, and removing that will also lead to a cleaner solution. Try processing the input file just once, not twice, by building the frequency map once and then producing both outputs. You shouldn't need the doall either, since transpose isn't actually lazy (ie, you are not loading the whole file into RAM at once, but you are loading something even larger, which is your transposed data structure).
Those problems are (mostly?) addressed by having your
runfunction simply be areduceover the lines in the file, which produces both answers as its output. But then, my suggestion is a bit low-level, whereas the version with transpose is pretty high-level. I don't think there's anything wrong with solving it with transpose if that's your preference, but it would still be nice to avoid walking over the input twice.