Long stairs: Difference between revisions

added RPL
(Added Gambas y PureBasic)
(added RPL)
 
(One intermediate revision by one other user not shown)
Line 568:
Average final length of staircase: 14707.466000
</pre>
 
=={{header|Dart}}==
{{trans|C}}
<syntaxhighlight lang="dart">import 'dart:math';
 
void main() {
int secsTot = 0,
stepsTot = 0; // keep track of time and steps over all the trials
Random rand = new Random();
 
print("Seconds steps behind steps ahead");
 
for (int trial = 1; trial <= 10000; trial++) {
// 10000 attempts for the runner
int sbeh = 0, slen = 100, secs = 0; // initialise this trial
 
while (sbeh < slen) {
// as long as the runner is still on the stairs
sbeh += 1; // runner climbs a step
 
for (int wiz = 1; wiz <= 5; wiz++) {
// evil wizard conjures five new steps
if (rand.nextInt(slen) < sbeh)
sbeh += 1; // maybe a new step is behind us
slen += 1; // either way, the staircase is longer
}
 
secs += 1; // one second has passed
 
if (trial == 1 && 599 < secs && secs < 610)
print("$secs $sbeh ${slen - sbeh}");
}
 
secsTot += secs;
stepsTot += slen;
}
 
print("Average secs taken: ${secsTot / 10000.0}");
print("Average final length of staircase: ${stepsTot / 10000.0}");
}</syntaxhighlight>
{{out}}
<pre>Similar as C entry.</pre>
 
=={{header|Factor}}==
Line 1,365 ⟶ 1,407:
609 2187 958
Average seconds: 2716.0197, Average steps: 13677.143</pre>
 
=={{header|RPL}}==
« 0 (100,100)
'''DO''' SWAP 1 +
SWAP 1 -
1 5 '''START'''
RAND OVER RE LASTARG IM / <
1 R→C +
'''NEXT'''
'''IF''' OVER 599 > 3 PICK 610 < AND '''THEN''' OVER 1 DISP DUP 2 DISP '''END'''
'''UNTIL''' DUP RE NOT '''END'''
IM "steps" →TAG SWAP "secs" →TAG
» '<span style="color:blue">STAIRS</span>' STO
{{out}}
<pre>
2: steps:16135
1: secs:3207
</pre>
Executing 10,000 tests is far beyond the computing power of a basic calculator.
 
=={{header|V (Vlang)}}==
1,150

edits