20 lines
517 B
Haskell
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
|