diff --git a/2019/day18/day18.hs b/2019/day18/day18.hs index 50df3a8..b30e15a 100644 --- a/2019/day18/day18.hs +++ b/2019/day18/day18.hs @@ -75,20 +75,14 @@ distanceFromTo dMap schar echar = findPos :: Char -> DungeonMap -> V2 Int findPos c = head . M.keys . M.filter (`elem` [c]) --- tracePath :: DungeonMap -> Char -> String -> Maybe Int --- tracePath dMap _ [] = Just 0 --- tracePath dMap c (x:xs) = case distanceFromTo dMap c x of --- Nothing -> Nothing --- Just y -> let trace = tracePath dMap c xs in if isJust trace then Just (y + fromJust trace) else Nothing tls1 :: DungeonMap -> S.Set Char -> Char -> Distance tls1 dMap nodeSet goal - | S.size nodeSet == 1 = (distanceFromTo dMap '@' (head $ S.toList nodeSet)) + | S.size nodeSet == 1 = distanceFromTo dMap '@' (head $ S.toList nodeSet) -- ^ S = {c}, different 1 element sets possible? | otherwise = minimum - [tls1 dMap sMinusC x + distanceFromTo newDMap x goal | x <- S.toList sMinusC] + [tls1 newDMap sMinusC x + distanceFromTo newDMap x goal | x <- S.toList sMinusC, + let newDMap = M.insert door '⌂' dMap + door = findPos (toUpper (traceShowId x)) dMap] where - sMinusC = traceShowId (S.delete goal nodeSet) - newDMap = traceShowId (M.insert door '⌂' dMap) - door = traceShowId (findPos (toUpper (traceShowId goal)) dMap) --- tls2 = undefined + sMinusC = S.delete goal nodeSet