-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay15.hs
35 lines (26 loc) · 787 Bytes
/
Day15.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
module Day15
( part1
, part2
) where
import Data.Text (Text)
import Helpers.Parsers.Text (signedInts)
data Disc =
Disc Index Positions Start
deriving (Show, Eq, Ord)
type Index = Int
type Positions = Int
type Start = Int
canFallThrough :: Int -> Disc -> Bool
canFallThrough t (Disc a b c) = (c + t + a) `mod` b == 0
makeDisc :: [Int] -> Disc
makeDisc [a, b, _, c] = Disc a b c
part1 :: Bool -> Text -> String
part1 _ input =
show . head . filter (\x -> all (canFallThrough x) discs) $ [0 ..]
where
discs = map makeDisc . signedInts $ input
part2 :: Bool -> Text -> String
part2 _ input =
show . head . filter (\x -> all (canFallThrough x) discs) $ [0 ..]
where
discs = (Disc 7 11 0 :) . map makeDisc . signedInts $ input