-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay06.hs
37 lines (33 loc) · 826 Bytes
/
Day06.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
-- |
-- Module : AOC2022.Day06
-- License : BSD3
--
-- Stability : experimental
-- Portability : non-portable
--
-- Day 6. See "AOC.Solver" for the types used in this module!
module AOC2022.Day06 (
day06a,
day06b,
)
where
import AOC.Common (charFinite, firstRepeatedFinitary, slidingWindows)
import AOC.Solver ((:~>) (..))
import Data.Finite (Finite)
import Data.Foldable (toList)
import Data.List (findIndex)
import Data.Maybe (isNothing, mapMaybe)
day06 :: Int -> [Finite 26] :~> Int
day06 n =
MkSol
{ sParse = Just . map snd . mapMaybe charFinite
, sShow = show
, sSolve =
fmap (+ n)
. findIndex (isNothing . firstRepeatedFinitary . toList)
. slidingWindows n
}
day06a :: [Finite 26] :~> Int
day06a = day06 4
day06b :: [Finite 26] :~> Int
day06b = day06 14