aboutsummaryrefslogtreecommitdiff
path: root/execs
diff options
context:
space:
mode:
Diffstat (limited to 'execs')
-rw-r--r--execs/Day10.hs29
1 files changed, 29 insertions, 0 deletions
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 @@
1
2module Main where
3
4import Utils
5import Data.List (sort)
6import Control.Monad
7import Control.Monad.Memo
8
9parseLine :: String -> Int
10parseLine = read
11
12diffs :: [Int] -> Int
13diffs s = product $ ($ q s) <$> [howMany (==1), howMany (==3)]
14 where q = zipWith subtract `ap` tail
15
16combos top s = startEvalMemo $ go 0
17 where go c
18 | c == top = return 1
19 | otherwise = do
20 let cs = filter (`elem` s) $ map (+c) [1,2,3]
21 sum <$> mapM (memo go) cs
22
23main :: IO ()
24main = do
25 n <- map parseLine . lines <$> readFile "input/10"
26 let top = maximum n + 3
27 ls = sort (0:top:n)
28 print $ diffs ls
29 print $ combos top ls