i'm making a recursive solution to a jump it game.
0 3 80 56 7 10
i ca either move forward 1 or jump over 1 to thereby move 2. The goal is to get the lowest amount.
I've been thinking of doing the total-move1<total-move2 move to 1
basically have the largest number at the end be the most effcient method. I'm wondering if I'm on the right track, and i dont know how i would go about making something recursive, a for loop maybe? since it does a pretest to see which is lower?
and i dont know how i would go about making something recursive, a for loop maybe?
For loops are iterative, not recursive.
Recursion means to have a function call itself.
Something like this would be a recursive solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int BestPath(int pos)
{
if( /* pos is at the end of the buffer */ )
{
return buffer[/*last value*/];
}
else
{
int one = BestPath(pos+1);
int two = BestPath(pos+2);
return min(one,two) + buffer[pos];
}
}