-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day2.hs
31 lines (26 loc) · 782 Bytes
/
Day2.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
module Day2
( part1
, part2
) where
import Helpers.Parsers (alpha, complexParser, numsAsStrings)
validate :: [String] -> Bool
validate [a, b, [c], d] = length pruned <= read b && length pruned >= read a
where
pruned = filter (== c) d
otherValidate :: [String] -> Bool
otherValidate [a, b, [c], d] = (da || db) && not (da && db)
where
da = d !! (read a - 1) == c
db = d !! (read b - 1) == c
part1 :: Bool -> String -> String
part1 _ =
show .
length .
filter validate .
map concat . complexParser ["-", " ", ": "] [numsAsStrings, numsAsStrings, alpha, alpha]
part2 :: Bool -> String -> String
part2 _ =
show .
length .
filter otherValidate .
map concat . complexParser ["-", " ", ": "] [numsAsStrings, numsAsStrings, alpha, alpha]