Stair-climbing puzzle: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 384:
Climbed up to 0
Climbed up to 1</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
{Recursive version}
 
procedure Step_Up;
begin
while not Step do Step_Up;
end;
 
{Iterative version}
 
procedure Step_Up;
var I: integer;
begin
while I<1 do
if Step then Inc(I) else Dec(I);
end;
 
<syntaxhighlight lang="Delphi">
var Position: integer;
 
function Step(Memo: TMemo): boolean;
begin
Result:=Random(2)=1;
if Result then Inc(Position)
else Dec(Position);
If Result then Memo.Lines.Add(Format('Climbed up to %d', [Position]))
else Memo.Lines.Add(Format('Fell down to %d', [Position]));
end;
 
 
procedure StepUp(Memo: TMemo);
begin
while not Step(Memo) do StepUp(Memo);
end;
 
 
procedure ShowStairClimb(Memo: TMemo);
begin
Position:=0;
Randomize;
StepUp(Memo);
end;
 
</syntaxhighlight>
{{out}}
<pre>
Fell down to -1
Climbed up to 0
Fell down to -1
Climbed up to 0
Climbed up to 1
Elapsed Time: 4.600 ms.
 
</pre>
 
 
 
=={{header|E}}==
465

edits