Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Map
- import Data.Char
- import Text.Regex.Posix
- cRoutes g [] _ _ _ = []
- cRoutes g (n:ns) p v rc
- | n == "end" = [p ++ ["end"]] ++ cRoutes g ns p v rc
- | isUpper (n !! 0) = cRoutes g (g ! n) (p++[n]) v rc ++ cRoutes g ns p v rc
- | notElem n v = cRoutes g (g ! n) (p++[n]) (n:v) rc ++ cRoutes g ns p v rc
- | rc == "" && n /= "start" = cRoutes g (g ! n) (p++[n]) v n ++ cRoutes g ns p v rc
- | otherwise = cRoutes g ns p v rc
- generateGraph [] m = m
- generateGraph (g:gs) m = let [[_,from,to]] = g =~ "(.*)-(.*)" :: [[String]]
- in generateGraph gs $ insertWith (++) from [to] $ insertWith (++) to [from] m
- main = do fileContent <- readFile "day12.in"
- let linesOfFile = lines fileContent
- graph = generateGraph linesOfFile Data.Map.empty
- print $ length $ cRoutes graph ["start"] [] [] "."
- print $ length $ cRoutes graph ["start"] [] [] ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement