From 5d217c1da271eeba6f902c6422ef316156dc1317 Mon Sep 17 00:00:00 2001 From: shu Date: Wed, 18 Dec 2019 19:06:56 +0100 Subject: [PATCH] =?UTF-8?q?Day=2018:=20Travelling=20salesman=20doesn?= =?UTF-8?q?=E2=80=99t=20wanna=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implementation should be complete in any case --- 2019/day18/day18.hs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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