I've read this SO question on how to rotate a two-dimensional array many times, and I was curious as to how you could expand this situation to work with a section of a two-dimensional array. I've thought about it for a while, and I can't seem to come up with a good equation. Essentially what I'm wanting to do is something like this:
1 2 3 4 5 6 13 7 1 4 5 6 7 8 9 10 11 12 14 8 2 10 11 12 13 14 15 16 17 18 15 9 3 16 17 18 19 20 21 22 23 24 ----> 19 20 21 22 23 24 25 26 27 28 29 30 25 26 27 28 29 30 31 32 33 34 35 36 31 32 33 34 35 36
I'm writing this in Ruby, currently, but I don't particularly care what language the solution to this kind of problem would be. I'm just curious as to how you'd go about solving this kind of problem.
Edit: To add some more specifics, the basic parameters for a function that could do this would be something that looked like this
def rotate(array, times=1, x=0, y=0, len=nil)
...
end