day3 part1
This commit is contained in:
parent
ef0c56b784
commit
24da3016c5
13
2021/day03/day03.hs
Normal file
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
1000
2021/day03/input
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user