monadic version of day21
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user