module Main where import Utils import Data.List (sort) import Control.Monad import Control.Monad.Memo parseLine :: String -> Int parseLine = read diffs :: [Int] -> Int diffs s = product $ ($ q s) <$> [howMany (==1), howMany (==3)] where q = zipWith subtract `ap` tail combos top s = startEvalMemo $ go 0 where go c | c == top = return 1 | otherwise = do let cs = filter (`elem` s) $ map (+c) [1,2,3] sum <$> mapM (memo go) cs main :: IO () main = do n <- map parseLine . lines <$> readFile "input/10" let top = maximum n + 3 ls = sort (0:top:n) print $ diffs ls print $ combos top ls