-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay12.hs
28 lines (22 loc) · 872 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
26
27
28
{-# LANGUAGE TupleSections #-}
module Day12
( part1
, part2
) where
import Data.Graph.Inductive.Graph (mkUGraph)
import Data.Graph.Inductive.Query.DFS (components)
import Data.Set (fromList, toList)
import Helpers.Graph (Gr)
import Helpers.Parsers (numbers)
type System = Gr () ()
buildGraph :: [[Int]] -> System
buildGraph pipes = mkUGraph nodes (outEdges ++ inEdges)
where
outEdges = concatMap (\(x:xs) -> map (x, ) xs) pipes
inEdges = concatMap (\(x:xs) -> map (, x) xs) pipes
nodes = toList . fromList . concat $ pipes
part1 :: Bool -> String -> String
part1 _ =
show . length . head . filter (elem 0) . components . buildGraph . numbers
part2 :: Bool -> String -> String
part2 _ = show . length . components . buildGraph . numbers