I realized having to host this potentially indefinitely might not be the best idea, so I am going to shut down this gitea instance eventually.
You’ll have time, at least until the end of 2022, probably longer, but please just get all your stuff somewhere safe in case we ever disappear.
If any of your build scripts rely on my (kageru’s) projects hosted here, check my Github or IEW on Github for encoding projects. If you can’t find what you’re looking there, tell me to migrate it.

Day 18: Travelling salesman doesn’t wanna work

Implementation should be complete in any case
master
shu 3 years ago
parent aecf61358f
commit 5d217c1da2
  1. 16
      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

Loading…
Cancel
Save