-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay01.hs
38 lines (33 loc) · 781 Bytes
/
Day01.hs
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
30
31
32
33
34
35
36
37
38
-- |
-- Module : AOC2021.Day01
-- License : BSD3
--
-- Stability : experimental
-- Portability : non-portable
--
-- Day 1. See "AOC.Solver" for the types used in this module!
module AOC2021.Day01 (
day01a,
day01b,
) where
import AOC.Common (countTrue, laggedPairs)
import AOC.Solver ((:~>) (..))
import Text.Read (readMaybe)
parseInput :: String -> Maybe [Int]
parseInput = traverse readMaybe . lines
countIncreases :: Int -> [Int] -> Int
countIncreases n = countTrue (uncurry (<)) . laggedPairs n
day01a :: [Int] :~> Int
day01a =
MkSol
{ sParse = parseInput
, sShow = show
, sSolve = Just . countIncreases 1
}
day01b :: [Int] :~> Int
day01b =
MkSol
{ sParse = parseInput
, sShow = show
, sSolve = Just . countIncreases 3
}