19 lines
498 B
Haskell
19 lines
498 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 (last . trib [0, 0, 1] . sum) . filter (elem 1) . group . jolts)
|
|
input
|
|
|
|
jolts :: [Integer] -> [Integer]
|
|
jolts = ap (zipWith subtract) tail . (\x -> 0 : x ++ [last x + 3]) . sort
|
|
|
|
trib :: [Integer] -> Integer -> [Integer]
|
|
trib x 0 = x
|
|
trib [x, y, z] n = trib [y, z, x + y + z] (n - 1)
|