q
Size: a a a
q
q
G
G
q
q
k
KS
k
q
KS
q
q
q
KS
G
grid = [ [1, 8, 8, 4]
, [10, 1, 1, 3]
, [1, 3, 12, 2]
, [2, 3, 5, 6]
]
gridSize = length grid
(<+>) (a, b) (c, d) = (a + c, b + d)
(<^>) l (a, b) = l !! a !! b;
filt = (== (des, des)) . foldl (<+>) (0, 0) where des = gridSize - 1
moves = filter filt . mapM (const [(1, 0), (0, 1)]) $ [1 .. 2 * (gridSize - 1)]
run = foldl (\(pos, c) move -> (pos<+>move, c+grid<^>pos)) ((0, 0), lastPt)
where lastPt = grid <^> (i, i)
i = gridSize - 1
main = do
let prices = map (snd . run) moves
print $ minimum prices
print $ maximum prices
Д
grid = [ [1, 8, 8, 4]
, [10, 1, 1, 3]
, [1, 3, 12, 2]
, [2, 3, 5, 6]
]
gridSize = length grid
(<+>) (a, b) (c, d) = (a + c, b + d)
(<^>) l (a, b) = l !! a !! b;
filt = (== (des, des)) . foldl (<+>) (0, 0) where des = gridSize - 1
moves = filter filt . mapM (const [(1, 0), (0, 1)]) $ [1 .. 2 * (gridSize - 1)]
run = foldl (\(pos, c) move -> (pos<+>move, c+grid<^>pos)) ((0, 0), lastPt)
where lastPt = grid <^> (i, i)
i = gridSize - 1
main = do
let prices = map (snd . run) moves
print $ minimum prices
print $ maximum prices
RN
RN