Day 18: Travelling salesman doesn’t wanna work
Implementation should be complete in any case
This commit is contained in:
parent
aecf61358f
commit
5d217c1da2
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user