Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
some progress day 23
Browse files Browse the repository at this point in the history
  • Loading branch information
mstksg committed Dec 23, 2023
1 parent 036a93a commit a328e69
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions src/AOC/Challenge/Day23.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,44 @@ data HikeState2 = HS2 {hs2Seen :: Set Point, hs2Curr :: Point, hs2Length :: Int}
deriving stock (Eq, Ord, Show, Generic)
deriving anyclass (NFData)

paths2 :: Map Point (NEMap Point Int) -> Int
paths2 gr = go 0 (Seq.singleton st0)
-- paths2 :: Map Point (NEMap Point Int) -> Int
-- paths2 gr = go 0 (Seq.singleton st0)
-- where
-- st0 = HS2 S.empty (V2 1 0) 0
-- goal = maximumBy (comparing $ view _y) (M.keys gr)
-- go !best = \case
-- Seq.Empty -> best
-- HS2{..} Seq.:<| xs
-- | hs2Curr == goal -> go (max best hs2Length) xs
-- | otherwise ->
-- let nexts = flip mapMaybe (toList (NEM.toList (gr M.! hs2Curr))) \(p, d) -> do
-- guard $ p `S.notMember` hs2Seen
-- pure $ HS2 (S.insert p hs2Seen) p (hs2Length + d)
-- in go best (xs <> Seq.fromList nexts)

paths2 :: Map Point (NEMap Point Int) -> Map HikeState [HikeState]
paths2 gr = go M.empty (M.singleton st0 [])
where
st0 = HS2 S.empty (V2 1 0) 0
st0 = HS S.empty (V2 1 0)
goal = maximumBy (comparing $ view _y) (M.keys gr)
go !best = \case
Seq.Empty -> best
HS2{..} Seq.:<| xs
| hs2Curr == goal -> go (max best hs2Length) xs
| otherwise ->
let nexts = flip mapMaybe (toList (NEM.toList (gr M.! hs2Curr))) \(p, d) -> do
guard $ p `S.notMember` hs2Seen
pure $ HS2 (S.insert p hs2Seen) p (hs2Length + d)
in go best (xs <> Seq.fromList nexts)
go res queue = case M.minViewWithKey queue of
Nothing -> res
Just ((x@HS{..},hist), xs)
| hsCurr == goal -> go (M.insertWith biggerSize x hist res) queue
| otherwise -> _
biggerSize x y = x

-- \case
-- Seq.Empty -> []
-- HS2{..} Seq.:<| xs
-- | hs2Curr == goal -> go (max best hs2Length) xs
-- | otherwise ->
-- let nexts = flip mapMaybe (toList (NEM.toList (gr M.! hs2Curr))) \(p, d) -> do
-- guard $ p `S.notMember` hs2Seen
-- pure $ HS2 (S.insert p hs2Seen) p (hs2Length + d)
-- in go best (xs <> Seq.fromList nexts)


-- pathGraph :: Set Point -> Map Point (NEMap Point Int)

-- pathGraph :: Set Point -> Map Point (NESet Point)
Expand Down

0 comments on commit a328e69

Please sign in to comment.