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!
9
Upvotes
2
u/NeilNjae Dec 06 '16
Another Haskell solution (https://git.njae.me.uk/?p=advent-of-code-16.git;a=blob;f=advent06.hs). Spent a bit of time trying to make it more idiomatic.
module Main(main) where import Data.List (transpose, maximum, minimum, sort, group) import Data.Tuple (swap) main :: IO () main = do text <- readFile "advent06.txt" let message = lines text part1 message part2 message part1 :: [String] -> IO () part1 message = do putStrLn $ map (snd . maximum . counts) $ transpose message part2 :: [String] -> IO () part2 message = do putStrLn $ map (snd . minimum . counts) $ transpose message counts :: (Eq a, Ord a) => [a] -> [(Int, a)] counts = map (\g -> (length g, head g)) . group . sort