M.findWithDefault (maxBound :: Int) (CacheKey a b level) cache
cheapestCostMove :: Button a => Cache -> Int -> (a, a) -> Int
-cheapestCostMove cache level (a, b) = minimum $ fmap (sequenceCostUsingCache cache level) stepChoices
+cheapestCostMove cache level (a, b) =
+ minimum $ fmap (sequenceCostUsingCache cache level) stepChoices
where stepChoices = moveBetween (a, b)
buildCache :: Int -> Cache
extendCache cache level = foldl' go cache allPairs
where
allPairs = [(a, b) | a <- [R .. A], b <- [R .. A]]
- go c (a, b) = M.insert (CacheKey a b level) (cheapestCostMove c (level - 1) (a, b)) c
+ go c (a, b) = M.insert (CacheKey a b level)
+ (cheapestCostMove c (level - 1) (a, b)) c
cache1 :: Cache
cache1 = M.fromList $ fmap go allPairs