I'm trying to figure out how to write a function that takes two integers, n and k, and finds all strictly decreasing sequences of length k of integers that are from 0 to n.
For example, allDecreasing(5, 3) returns
[[4,3,2], [4,3,1], [4,3,0], [4,2,1], [4,2,0], [4,1,0], [3,2,1], [3,2,0], [3,1,0], [2,1,0]]
So far, I only have:
function all-decreasing(n, k) {
if (n > k-1) {
all-decreasing(n-1, k);
}
}
It's not much, since I'm not quite sure how to approach the iteration part. Permutation and subset algorithms have always been confusing for me. If anyone could give me an idea on how to get started, it would be greatly appreciated! Thank you.