-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay2.hs
35 lines (30 loc) · 786 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
32
33
34
35
module Day2
( part1
, part2
) where
import Data.List (group, sort, tails)
import Data.Maybe (Maybe (Just, Nothing), catMaybes, isNothing)
findDifference :: [String] -> String
findDifference list =
catMaybes .
head .
filter ((== 1) . length . filter isNothing) .
concat .
zipWith
(map .
zipWith
(\a b ->
if a == b
then Just a
else Nothing))
(init list) $
tails list
checksum :: [[Int]] -> Int
checksum iDs = twos * threes
where
threes = length . filter (3 `elem`) $ iDs
twos = length . filter (2 `elem`) $ iDs
part1 :: Bool -> String -> String
part1 _ = show . checksum . map (map length . group . sort) . lines
part2 :: Bool -> String -> String
part2 _ = findDifference . lines