44a48767ef
This code is hilarious
22 lines
566 B
Haskell
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
|