With this function I generate needed ranges:
first_index = 0
last_index = 3
ranges = []
while first_index != last_index
while last_index != 0
if first_index < last_index
ranges << (first_index..last_index)
end
last_index -= 1
end
first_index += 1
last_index = 3
end
p ranges
The output is:
[0..3, 0..2, 0..1, 1..3, 1..2, 2..3]
I need to revert the output of the nested while loop, after it finishes. So in this example, I need:
[0..3, 0..2, 0..1].reverse
[1..3, 1..2].reverse
[2..3].reverse (wouldn't make any different on this, though)
The output I would get is:
[0..1, 0..2, 0..3, 1..2, 1..3, 2..3]
Can I invoke reverse somehow in that function? last_index could be any integer. I used 3 just to shorten the output.
(0..3).to_a.combination(2).map { |a, b| a..b }returns the ranges in the expected order.