A lottery draw consists of choosing 6 different values from 1 to 50.
I want to calculate the number of combinations with gaps of at least 3 between every pair of values.
I have used the following Python 2.7 script:
def func(array,length,min,max,gap): if len(array) == length: # print array return 1 count = 0 for n in range(min,max+1): count += func(array+[n],length,n+gap,max,gap) return count; print func(,6,1,50,3)
- Are there any coding improvements that I can apply?
- Is there a different method with which we can do it more efficiently?
- Although more suitable for math.stackexchange.com, is there a straightforward formula?