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.
end.</lang>
{{Out|@ TIO.RUN}}
<pre>
Seconds steps total behind ahead
600 3100 21712021 9291079
601 3105 21742027 9311078
602 3110 21782031 9321079
603 3115 21822036 9331079
604 3120 21872039 9331081
605 3125 21922043 9331082
606 3130 21962048 9341082
607 3135 22002052 9351083
608 3140 22042055 9361085
609 3145 22092059 9361086
average stairs minimum maximum
14691.943605 71957655 3076526770
 
2938.387319 average needed seconds</pre>
 
stairs without random
2938.387 average needed seconds</pre>
14470.00
</pre>
 
=={{header|Phix}}==
Anonymous user