Talk:Stair-climbing puzzle: Difference between revisions

m
(→‎Problem statement: ? recursion unnecessary and wrong? ?)
 
(One intermediate revision by one other user not shown)
Line 2:
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'. <span style="font-size: smaller;" class="autosigned">—Preceding unsigned comment added by [[Special:Contributions/71.59.209.100|71.59.209.100]]</span>
:Okay, I've made it more explicit. —[[User:Underscore|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 <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)
Anonymous user