13ecd8bad7
I hope, at least Lambdas are a bit easier to read I think
18 lines
511 B
Haskell
18 lines
511 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 =
|
|
(\x -> length . filter (== x)) <*>
|
|
(map sum . nub . map (filter (/= 0)) . flip replicateM [0 .. 3])
|
|
|
|
jolts :: [Int] -> [Int]
|
|
jolts = ap (zipWith subtract) tail . (\x -> 0 : x ++ [last x + 3]) . sort
|