-
Notifications
You must be signed in to change notification settings - Fork 5
/
Day12.hs
25 lines (20 loc) · 847 Bytes
/
Day12.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
module AOC2017.Day12 (day12a, day12b) where
import AOC2017.Types (Challenge)
import AOC2017.Util.Disjoints (Disjoints(..), disjoint)
import Data.Char (isDigit)
import Data.List (find)
import Data.Maybe (fromJust)
import qualified Data.IntSet as IS
import qualified Data.Set as S
parseLine :: String -> IS.IntSet
parseLine (words->n:_:ns) = IS.fromList $ read n
: map (read . filter isDigit) ns
parseLine _ = error "No parse"
build :: String -> Disjoints
build = foldMap (disjoint . parseLine) . lines
day12a :: Challenge
day12a = show . IS.size . fromJust . find (0 `IS.member`)
. getD . build
day12b :: Challenge
day12b = show . S.size
. getD . build