Jump to content

Stair-climbing puzzle: Difference between revisions

no edit summary
(Switch to puzzle category)
No edit summary
Line 3:
 
Your stair-climbing robot has a very simple low-level API: the "step" function takes no argument and attempts to climb one step as a side effect. Unfortunately, sometimes the attempt fails and the robot clumsily falls one step instead. The "step" function detects what happens and returns a boolean flag: true on success, false on failure. Write a function "step_up" that climbs one step up (by repeating "step" attempts if necessary). Assume that the robot is not already at the top of the stairs, and neither does it ever reach the bottom of the stairs. How small can you make "step_up"? Can you avoid using variables (even immutable ones) and numbers?
 
=={{header|C++}}==
<lang cpp>
void step_up()
{
while (!step()) step_up();
}
</lang>
 
=={{header|Clojure}}==
973

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.