AoC/2020/day10/day10.hs
2020-12-10 08:22:40 +01:00

20 lines
517 B
Haskell

import Control.Monad
import Data.List
main :: IO ()
main = do
input <- map read . lines <$> readFile "input"
print $ (product . map length . group . sort . jolts) input
print $
(product . map (arrangements . sum) . filter (elem 1) . group . jolts) input
arrangements :: Int -> Int
arrangements n =
length $
filter (== n) $ map sum $ nub $ map (filter (/= 0)) $ replicateM n [0 .. 3]
jolts :: [Int] -> [Int]
jolts =
ap (zipWith subtract) tail .
ap (++) (flip (:) [] . (+ 3) . last) . (:) 0 . sort