Choose k from n
Write combinations(n, k) that returns every way to choose k distinct numbers from
1 to n, each as an increasing list. Order of the output does not matter.
combinations(4, 2) -> [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
combinations(3, 3) -> [[1, 2, 3]]
combinations(3, 0) -> [[]]
The point is to practise the start index pattern with a size limit, and pruning when
too few numbers remain.
def combinations(n, k):
...