From 492ccb0a5df82f856e3d7c375ceea63ba75d95d4 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Tue, 12 Dec 2017 15:30:16 -0800 Subject: [PATCH] Day 12 - use array constructor instead of graphFromEdges, which needs and produces some extra stuff. --- 12_graph.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/12_graph.hs b/12_graph.hs index f4308df..80d87c6 100644 --- a/12_graph.hs +++ b/12_graph.hs @@ -1,13 +1,14 @@ import Data.List.Split (splitOn) -import Data.Graph (graphFromEdges, reachable, scc) +import Data.Graph (reachable, scc) +import Data.Array (array) -parseLine :: String -> (Int, Int, [Int]) +parseLine :: String -> (Int, [Int]) parseLine str = let src : dests : [] = splitOn " <-> " str - in (read src, read src, map read $ splitOn ", " dests) + in (read src, map read $ splitOn ", " dests) main :: IO () main = do - (graph, _, _) <- fmap (graphFromEdges . map parseLine . lines) $ readFile "12.txt" + graph <- fmap (array (0, 1999) . map parseLine . lines) $ readFile "12.txt" print $ length $ reachable graph 0 print $ length $ scc graph \ No newline at end of file