From edd8e1fa47c6895b28bbe61ab786ab6dc30471cd Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 11 Dec 2020 10:07:13 +0530 Subject: add day10 --- execs/Day10.hs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 execs/Day10.hs (limited to 'execs') diff --git a/execs/Day10.hs b/execs/Day10.hs new file mode 100644 index 0000000..c42a550 --- /dev/null +++ b/execs/Day10.hs @@ -0,0 +1,29 @@ + +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 -- cgit v1.2.3