blob: c42a5508632fa0a89f029798ca0979e7a43171e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
|