blob: 826fc65d9c7a8e7b42f8d4424cdcfabe5e48d1fe (
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
|
module Main where
import Control.Monad
import Control.Monad.Memo
import Data.List (sort)
import Utils
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 = sum <$> mapM (memo go) (filter (`elem` s) $ map (+c) [1,2,3])
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
|