enumerating combinations with minimum specified separation I am trying to figure out how to efficiently iterate through combinations of $m$ integers in the range (0,$n-1$) where there are separations of at least 3 (= at least two unused elements between each used element).
In other words, let's say I have $m=4$ and $n=16$; then the list of valid ordered combinations starts with:


*

*$0, 3, 6, 9$

*$0, 3, 6, 10$

*$0, 3, 7, 10$

*$0, 4, 7, 10$

*$0, 3, 6, 11$

*$0, 3, 7, 11$

*$0, 4, 7, 11$

*$0, 3, 8, 11$

*$0, 4, 8, 11$

*$0, 5, 8, 11$


(etc.)
Is there an easy way to do this? I can't even think of a way to automate it, except for small values of $m$ where I explicitly throw away invalid combinations.
(bonus points if there's a way to do it with python's itertools.combinations or something similar)
 A: Oh -- I think I figured part of it out using stars and bars (I can never remember that technique unless I find a link to it)
With $m=4$ and $n=16$ for example, there are 3 spaces between items so that puts 6 items "out of commission" (minimum possible $n=10$ which has the only solution $0, 3, 6, 9$). The remaining 10 items can use stars and bars with 4 stars (for the $m=4$ items) and 6 bars. Then I can create a one-to-one correspondence between the stars-and-bars patterns with the output tuple, where each bar represents an extra space:


*

*****------ = $0, 3, 6, 9$ 

****-*----- = $0, 3, 6, 10$

***-**----- = $0, 3, 7, 10$

**-***----- = $0, 4, 7, 10$

*-****----- = $1, 4, 7, 10$ (which I originally forgot to mention in the problem statement)

****--*---- = $0, 3, 6, 11$

***-*-*---- = $0, 3, 7, 11$


and so on.
The number of possibilities is ${10\choose4} = 210$.
In general it looks like the number of possibilities for a gap $g=2$ is ${n-g(m-1)\choose m}$.
I can convert a conventional iterator over combinations (10,4) to this approach in Python as follows:
for combo in combinations(range(10),4)
    # combo iterates over (0,1,2,3), (0,1,2,4), (0,1,3,4), (0,2,3,4), etc.
    derived_combo = [c+g*k for k,c in enumerate(combo)]

