day3 part1

This commit is contained in:
Gattix 2021-12-05 23:26:29 +01:00
parent ef0c56b784
commit 24da3016c5
2 changed files with 1013 additions and 0 deletions

13
2021/day03/day03.hs Normal file

@ -0,0 +1,13 @@
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

1000
2021/day03/input Normal file

File diff suppressed because it is too large Load Diff