Talk:Stair-climbing puzzle: Difference between revisions
(→Problem statement: ? recursion unnecessary and wrong? ?) |
|||
Line 10: | Line 10: | ||
</lang> |
</lang> |
||
would work? Why is used recursion if indeed <tt>step_up</tt> does nothing more? ... --[[User:ShinTakezou|ShinTakezou]] 10:30, 7 November 2009 (UTC) |
would work? Why is used recursion if indeed <tt>step_up</tt> does nothing more? ... --[[User:ShinTakezou|ShinTakezou]] 10:30, 7 November 2009 (UTC) |
||
Moreover... maybe I am loosing bits however: the recursive C++ solution does not work... Let us suppose the first call to step fails, so that it returns false and the step_up is called again; now let us suppose that at this first level of recursion the step() is successful; the loop exit and control returns to the caller which repeat the loop, that re-execute the step() function... so let imagine now it is successful... this would mean we climbed two steps, not one... I set up my codes to avoid this; if someone explain me why I am wrong I will fix (if time allows:/) --[[User:ShinTakezou|ShinTakezou]] 10:39, 7 November 2009 (UTC) |
Revision as of 10:39, 7 November 2009
Problem statement
The problem is ambiguous as stated. It says to climb one step up, not climb up one step up from the starting position. Thus the original C# code that was there solved the 'climb one step up'. —Preceding unsigned comment added by 71.59.209.100
- Okay, I've made it more explicit. —Underscore 00:30, 7 November 2009 (UTC)
Am I wrong or recursion can be simply avoided since the "action" is done indeed into step? So the following C code <lang c> void step_up() {
while ( !step() ) ;
} </lang> would work? Why is used recursion if indeed step_up does nothing more? ... --ShinTakezou 10:30, 7 November 2009 (UTC) Moreover... maybe I am loosing bits however: the recursive C++ solution does not work... Let us suppose the first call to step fails, so that it returns false and the step_up is called again; now let us suppose that at this first level of recursion the step() is successful; the loop exit and control returns to the caller which repeat the loop, that re-execute the step() function... so let imagine now it is successful... this would mean we climbed two steps, not one... I set up my codes to avoid this; if someone explain me why I am wrong I will fix (if time allows:/) --ShinTakezou 10:39, 7 November 2009 (UTC)