I have an array, say
ar = [1,2,3,4,5]
I need to find a list of arrays (or a matrix) that contains an all possible ways to split this array into exhaustive sets of pairs.
eg.
[
[[1,2],[3,4],[5]],
[[1,2],[3,5],[4]],
[[1,2],[4,5],[3]],
[[1,3],[2,4],[5]]
...
[[1,5],[3,4],[2]]
]
Please try to use pseudocode, or refrain from using language-specific functions