monadic version of day21

This commit is contained in:
2024-12-21 21:02:56 -08:00
parent e396514899
commit 2c7c5eca55
4 changed files with 184 additions and 5 deletions

View File

@@ -71,11 +71,10 @@ seqCost : Point → List Point → Keypad × Int → Keypad × Int
seqCost cur Nil (kp, cost) = (kp, cost)
seqCost cur (pt :: pts) (kp, cost) =
let (kp, cost') = pathCost cur pt kp in
let x = cost' in
seqCost pt pts (kp, cost + cost')
-- cost of best path from -> to in kp
pathCost from to kp = do
pathCost from to kp =
case lookupMap (from, to) (costs kp) of
Just (_, cost) => (kp, cost)
Nothing =>
@@ -124,6 +123,7 @@ run fn = do
-- the space is illegal spot
let numpad = fromList $ filter (not _==_ ' ' fst) $ gridPoints "789\n456\n123\n 0A"
debugLog $ toList numpad
let rob1 = KP "r1" (0,2) (0,0) EmptyMap Nothing
let robn = makeKeypad 2 rob1