What I have
a = [1,2,3,4]
=> [1, 2, 3, 4]
b = a.combination(2).to_a
=> [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
b.each_slice(2).to_a
=> [[[1, 2], [1, 3]], [[1, 4], [2, 3]], [[2, 4], [3, 4]]]
What I'm trying to achieve is a unique combination
=> [[[1, 2], [3, 4]], [[1, 4], [2, 3]], [[1, 3], [2, 4]]]
I have tried with permutation, flatten, &c. but cannot find the magic ruby code!
Edit :
The answer above is like
b = a.combination(2).to_a
=> [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
To be more precise.
From
a = [1,2,3,4,5,6]
how to get
=> [[[1, 2], [3, 4], [5, 6]], [[1, 3], [2, 5], [4, 6]], [[1, 4], [2, 6], [3, 5]], [[1, 5], [2, 4], [3, 6]], [[1, 6], [2, 3], [4, 5]]]
which is 5 arrays of uniq values (1,2,3,4,5,6):
[1, 2], [3, 4], [5, 6]
[1, 3], [2, 5], [4, 6]
[1, 4], [2, 6], [3, 5]
[1, 5], [2, 4], [3, 6]
[1, 6], [2, 3], [4, 5]
You seem to have changed the question. Originally you wanted an array of arrays, each of >which had a pair of arrays. Now you want triplets?
Yes, because the first exemple with [1,2,3,4] was too easy, and the answer doesn't fit with a more complex array like [1,2,3,4,5,6] and so one.