aboutsummaryrefslogtreecommitdiff
path: root/execs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-12-11 04:37:13 +0000
committerAkshay <[email protected]>2020-12-11 04:37:13 +0000
commitedd8e1fa47c6895b28bbe61ab786ab6dc30471cd (patch)
treeea63292c4ce916c9f34ae8ed205f33dd2d3b9d88 /execs
parentac3191ae40b8df0873f2e04f5bc1017322941b5d (diff)
add day10
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