So here is my solution, it uses javascript, although it uses ES6 (for distribution using array parameters, by default, this will work fine in current versions of Firefox, I did it in Firefox 50):
function getHopPathsCnt(totalsteps, maxhopability, curstep = 0, taken = [], total={count:0}) { if (totalsteps === curstep) { total.count++; console.log('A possible hop path:', taken.join(' ')); } else { for (let hopped = 1; hopped <= maxhopability; hopped++) { if (totalsteps - curstep >= hopped) getHopPathsCnt(totalsteps, maxhopability, curstep + hopped, [...taken, hopped], total); } } if (curstep === 0) { console.error('Total ways to climb', totalsteps, 'steps with up to', maxhopability, 'hops at a time:', total.count); return total.count; } }
To use it:
getHopPathsCnt(3, 3);
Outputs:
Possible transition path: 1 1 1
Possible transition path: 1 2
Possible transition path: 2 1
Possible transition path: 3
Common ways to climb 3 steps with an accuracy of 3 jumps at a time: 4
4
The reason I provided a complete solution, unlike Gareth above
This problem looks like homework-y and for this reason I want to share it. Homework is designed to open new horizons. Therefore, sometimes, when I do not have a solution, I continue to force it with my “current skill / mentality”, which will never be able to get me. In the end, when I see the solution and work in the reverse order, he simply added a new facet to my “skill / mentality”. That's why I hate to see solutions say: "I will not fill in too many details because it seems to be homework-y." Since this leads to the only teaching method - the wrong solution to the problem, and then our stupid classification system gives us a bad class, and then "learn from our mistakes." I hate learning from mistakes if this can be avoided. I also probably will not be classified in the Wrong / F caste as a class, especially if I do my best. And it’s not always necessarily true that we learn from “mistakes”, especially when you were simply discarded by our rating system as “failure” / “wrong”.