AoC/2021/day03/day03.hs

14 lines
394 B
Haskell
Raw Normal View History

2021-12-05 23:26:29 +01:00
import Data.List
import Control.Lens
import Control.Arrow
main :: IO ()
main = do
input <- lines <$> readFile "input"
let counts = map ((\[x,y]->x>y) . map length . group . sort) $ transpose input
let (gamma,epsilon) = boolToDec *** boolToDec $ (id &&& map not) counts
print $ gamma * epsilon
boolToDec :: [Bool] -> Int
boolToDec = sum . imap (\x y->(2^x)*y) . reverse . map fromEnum