AoC/2020/day10/day10.hs
shu 44a48767ef Day 10
This code is hilarious
2020-12-10 08:05:45 +01:00

22 lines
566 B
Haskell

import Control.Arrow
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 =
map (uncurry subtract) .
ap zip tail .
uncurry (++) . (id &&& (flip (:) [] . (+ 3) . last)) . (:) 0 . sort