Number of combinations C(k,n) having max x interval between consecutive elements

Hi !

I am just stuck in a problem.

k = { 1,2,3,4,5,6,7,8,9,10 } set of positive integers

n = 4

x = 2

combination = { i1,i2,i3,i4 }

I want to find C(k,n) such that i2-i1 < x, i3-i2 < x , i4-i3 < x

I want a generalized method where the values of k,n,x can be changed.

Needed help

Senthil(Thinking)

yes looping is not feasible for larger values of k

I have tried looping for slightly higher values for k like > 128

since the combinations are exponential it is not feasible.

(Worried)