Long stairs: Difference between revisions

→‎{{header|Raku}}: Add a Raku example
(create new draft task; suggestions for clarity very welcome)
 
(→‎{{header|Raku}}: Add a Raku example)
Line 169:
190 PRINT TIMET/10000
200 PRINT STEPST/10000</lang>
 
=={{header|Raku}}==
<lang perl6>my ($trials, $t-total, $s-total) = 10000;
 
say 'Seconds steps behind steps ahead';
 
race for ^$trials {
my $stairs = 100;
my $location = 0;
my $seconds = 0;
 
loop {
$seconds++;
$location++;
last if $location > $stairs;
for (^$stairs).roll(5) {
$location++ if $_ <= $location;
$stairs++;
}
say " $seconds $location {$stairs-$location}" if !$_ && (599 < $seconds < 610);
}
 
$t-total += $seconds;
$s-total += $stairs;
}
 
say "Average seconds: {$t-total/$trials}, Average steps: {$s-total/$trials}";</lang>
{{out|Sample output}}
<pre>Seconds steps behind steps ahead
600 2143 957
601 2149 956
602 2153 957
603 2158 957
604 2164 956
605 2170 955
606 2175 955
607 2178 957
608 2183 957
609 2187 958
Average seconds: 2716.0197, Average steps: 13677.143</pre>
10,327

edits