Anonymous user
Long stairs: Difference between revisions
m
→{{header|Free Pascal}}: trying to calculate without random.Instead of random use ratio behind/total
(julia example) |
m (→{{header|Free Pascal}}: trying to calculate without random.Instead of random use ratio behind/total) |
||
Line 337:
inc(total)
end;
if WithOutput then
begin
Line 343 ⟶ 342:
OutActual(trials,behind,infront);
end;
until infront = 0;
OneRun := total;
end;
procedure CheckDouble;
//instead of random use ratio behind/total
var
//xmm in freepascal using SSE
behind,infront,relpos,total,One : double;
i : nativeInt;
begin
One := 1.0;
behind := 0.0;
inFront := StartStairLength;
total := StartStairLength;
repeat
//first: doing the step
behind += One;
inFront -= One;
//second: doing the spell
For i := StairsPerSpell-1 downto 0 do
begin
relpos := behind/total;
behind += relpos;
inFront += (One-relpos);
total += One;
end;
until infront < One;
writeln(total:10:2);
end;
Line 374 ⟶ 399:
writeln;
writeln((total-StartStairLength)/rounds/StairsPerSpell:10:3,' average needed seconds');
writeln;
end.</lang>▼
writeln(' stairs without random ');
CheckDouble;
end.
{{Out|@ TIO.RUN}}
<pre>
Seconds steps total behind ahead
600 3100
601 3105
602 3110
603 3115
604 3120
605 3125
606 3130
607 3135
608 3140
609 3145
average stairs minimum maximum
14691.
stairs without random
▲ 2938.387 average needed seconds</pre>
14470.00
</pre>
=={{header|Phix}}==
|