From dd002c175c6a2bd2fba8988efe84d0ccec96644e Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Tue, 12 Dec 2017 10:32:51 -0800 Subject: [PATCH] Day 12 - is it cheating if I use built-in graph functions? owo --- 12_graph.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 12_graph.hs diff --git a/12_graph.hs b/12_graph.hs new file mode 100644 index 0000000..f4308df --- /dev/null +++ b/12_graph.hs @@ -0,0 +1,13 @@ +import Data.List.Split (splitOn) +import Data.Graph (graphFromEdges, reachable, scc) + +parseLine :: String -> (Int, Int, [Int]) +parseLine str = + let src : dests : [] = splitOn " <-> " str + in (read src, read src, map read $ splitOn ", " dests) + +main :: IO () +main = do + (graph, _, _) <- fmap (graphFromEdges . map parseLine . lines) $ readFile "12.txt" + print $ length $ reachable graph 0 + print $ length $ scc graph \ No newline at end of file