Here are some suggestions, which should help reduce the use of indices
and local variables.
When constructing the array b, you don't need to reference a position.
You can start with an empty array, and push the new pairs onto the end:
instead of b = Array.new, write b = []
instead of b[k] = [a1, a2], write b << [a1, a2]
That gets rid of k.
To get the pairs, I suggest you investigate 'slice'.
e.g. a.slice(0, 2) returns a two-element array from the 0th position of
a: [1, 2]
You will also need to change your looping mechanism if you use slice,
but you should be able to get rid of a1 and a2.
--
Posted via http://www.ruby-forum.com/.