diff options
author | Akshay <[email protected]> | 2020-12-11 04:37:13 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-12-11 04:37:13 +0000 |
commit | edd8e1fa47c6895b28bbe61ab786ab6dc30471cd (patch) | |
tree | ea63292c4ce916c9f34ae8ed205f33dd2d3b9d88 /execs | |
parent | ac3191ae40b8df0873f2e04f5bc1017322941b5d (diff) |
add day10
Diffstat (limited to 'execs')
-rw-r--r-- | execs/Day10.hs | 29 |
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 | |||
2 | module Main where | ||
3 | |||
4 | import Utils | ||
5 | import Data.List (sort) | ||
6 | import Control.Monad | ||
7 | import Control.Monad.Memo | ||
8 | |||
9 | parseLine :: String -> Int | ||
10 | parseLine = read | ||
11 | |||
12 | diffs :: [Int] -> Int | ||
13 | diffs s = product $ ($ q s) <$> [howMany (==1), howMany (==3)] | ||
14 | where q = zipWith subtract `ap` tail | ||
15 | |||
16 | combos 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 | |||
23 | main :: IO () | ||
24 | main = 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 | ||