Long stairs: Difference between revisions

Content added Content deleted
(Added Wren)
(added header pascal)
Line 169: Line 169:
190 PRINT TIMET/10000
190 PRINT TIMET/10000
200 PRINT STEPST/10000</lang>
200 PRINT STEPST/10000</lang>
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<lang pascal>
program WizardStaircase;
const
StartStairLength = 100;
StairsPerSpell = 5;
rounds = 10000;
procedure OutActual(trials,behind,infront:Uint32);
begin
writeln(trials:5,infront+behind:12,behind:10,inFront:9);
end;


function OneRun(WithOutput:boolean):NativeUint;
var
inFront,behind,total,i,trials: Uint32;
begin
trials := 0;
total := StartStairLength;
inFront := total;
behind := 0;
repeat
inc(trials);
inc(behind);
dec(infront);
//spell
for i := 1 to StairsPerSpell do
begin
if random(total)+1 <= behind then
inc(behind)
else
inc(infront);
inc(total)
end;

if WithOutput then
begin
if (trials <= 609)AND(trials>=600) then
OutActual(trials,behind,infront);
end;

until infront = 0;
OneRun := total;
end;

var
i,
attempt,
minStairs,
maxStairs,
total : NativeUint;
begin
minStairs := High(minStairs);
maxStairs := low(maxStairs);
randomize;
writeln('Seconds steps total behind ahead');
OneRun(true);
total := 0;
For i := rounds-1 downto 0 do
begin
attempt:= OneRun(false);
if minStairs>attempt then
minstairs := attempt;
if maxStairs<attempt then
maxstairs := attempt;
inc(total,attempt);
end;
writeln(' average stairs minimum maximum');
writeln(total/rounds:14:3,minStairs:9,maxStairs:10);
writeln;
writeln((total-StartStairLength)/rounds/StairsPerSpell:10:3,' average needed seconds');
end.</lang>
{{Out|@ TIO.RUN}}
<pre>
Seconds steps total behind ahead
600 3100 2171 929
601 3105 2174 931
602 3110 2178 932
603 3115 2182 933
604 3120 2187 933
605 3125 2192 933
606 3130 2196 934
607 3135 2200 935
608 3140 2204 936
609 3145 2209 936
average stairs minimum maximum
14691.943 7195 30765

2938.387 average needed seconds</pre>
=={{header|Raku}}==
=={{header|Raku}}==
<lang perl6>my ($trials, $t-total, $s-total) = 10000;
<lang perl6>my ($trials, $t-total, $s-total) = 10000;