To give ourselves some ideas, let's start with illustrations.
Suppose the distance is 5 inches. s is step and j is jump. Then the solution would consist of:
5 steps solution:
s-s-s-s-s
4 steps solution:
s-s-s-j
s-s-j-s
s-j-s-s
j-s-s-s
3 steps solution:
s-j-j
j-s-j
j-j-s
And then another case when the distance is 4:
4 steps solution:
s-s-s-s
3 steps solution:
s-s-j
s-j-s
j-s-s
2 steps solution:
j-j
And another is when the distance is 6, we will have:
6 steps solution:
s-s-s-s-s-s
5:
s-s-s-s-j
s-s-s-j-s
s-s-j-s-s
s-j-s-s-s
j-s-s-s-s
4:
s-s-j-j
s-j-s-j
s-j-j-s
j-s-s-j
j-s-j-s
j-j-s-s
3:
j-j-j
Supposing the distance is D, from the illustration above, we can already derive few characteristics:
The number of possible number of actions (A) is [D=6, A=4; D=5, A=3; D=4; A=3]. We can also easily find [D=3, A=2; D=2, A=2; D=1, A=1]
Thus you see the pattern for A: 1,2,2,3,3,4. And for D:1,2,3,4,5,6. And you got your first relationship:
A = int(D/2) + 1
You also notice the next pattern. Take a look on the example for D=6. You have the following to count:
6 steps: given 6 take 0
5 steps: given 5 take 1
4 steps: given 4 take 2
3 steps: given 3 take 3
Here you find another pattern: note that this is combination problems. The result for D=6 is given by:
6C0 + 5C1 + 4C2 + 3C3
Also note that, suppose combination is noted by aCb, a keeps decreasing from D to D-A+1 while b increase from 0 to A-1.
Now knowing those pattern syou could easily solve the problem by:
- Creating a for loop from D to D-A+1.
- In that for loop you have two vars: a and b. a keeps increasing, b keeps decreasing
Create simple function which receives a & b and has operation of aCb.
http://www.mathwords.com/c/combination_formula.htm
aCb = a!/(b!(a-b)!)
Sum the result in each loop of the for loop.
And you are done!