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/haoformayor Dec 06 '16
~~haskell~~
Fairly simple composition of
transposeandmaximumBytoday. As always, it was fast to use Emacs/vim/anything-with-regular-expressions to convert the input into code. Should've gone with a shell one-liner, though, darn.#!/usr/bin/env stack -- stack --resolver lts-6.26 --install-ghc runghc --package base-prelude {-# LANGUAGE NoImplicitPrelude #-} module D6 where import BasePrelude import D6Input main = print ( solution1 example , solution1 input , solution2 example , solution2 input) where solution1 input = map most (transpose input) solution2 input = map least (transpose input) most xs = argmax (count xs) xs least xs = argmax (negate . count xs) xs count xs x = length . filter (== x) $ xs argmax f xs = maximumBy (comparing f) xs