Skip to content

Instantly share code, notes, and snippets.

@fffej
Created July 26, 2014 11:13
Show Gist options
  • Select an option

  • Save fffej/ca5b93da956f8bb6842e to your computer and use it in GitHub Desktop.

Select an option

Save fffej/ca5b93da956f8bb6842e to your computer and use it in GitHub Desktop.
WarpingPath
warpingPath :: Array (Int,Int) Int -> [(Int,Int)]
warpingPath arr = go (w,h) []
where
(_,(w,h)) = bounds arr
go p@(x,y) xs
| x == 0 && y == 0 = p : xs
| otherwise = go minVal (minVal : xs)
where
minVal = minimumBy (comparing (arr !)) [down,downLeft,left]
down = (max 0 (x-1),max 0 y)
left = (x,max 0 (y-1))
downLeft = (max 0 (x-1),max 0 (y-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment