Day 12 - use array constructor instead of graphFromEdges, which needs and produces some extra stuff.
This commit is contained in:
parent
dd002c175c
commit
492ccb0a5d
|
@ -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
|
Loading…
Reference in New Issue