diff options
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 | ||