It is a bit difficult to explain but I'll try.
Lets say that we know how to solve GetXFromNumbers where x = 2 and we need to solve it for x = 3.
The numbers are 1, 2, 3, 4, 5, 6.
As the order of numbers doesn't matter, we always keep the numbers in the same order.
First step is to find all solutions where 1 is the first number:
1, 2, 3
1, 2, 4
1, 2, 5
1, 2, 6
1, 3, 3
...
This is equivalent to solving: GetXFromNumbers (2, Array(2, 3, 4, 5, 6))
And then add 1 as the first item of each result.
All solutions are the union of:
1 is the first number, GetXFromNumbers (2, Array(2, 3, 4, 5, 6))
2 is the first number, GetXFromNumbers (2, Array(3, 4, 5, 6))
3, GetXFromNumbers (2, Array(4, 5, 6))
4, GetXFromNumbers (2, Array(5, 6))
This is the algorithm behind the code above.