Jump to content

Long stairs: Difference between revisions

3,561 bytes added ,  2 months ago
Added Gambas y PureBasic
(Grouping BASIC dialects)
(Added Gambas y PureBasic)
Line 263:
Average final staircase length: 14709.7285 steps.
</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
 
Randomize
Dim steps_behind As Integer = 0, stairs_length As Integer = 100, seconds As Integer
Dim seconds_tot As Integer, steps_tot As Integer, j As Integer
Print "Seconds", "steps behind", "steps ahead"
For trial As Integer = 1 To 10000 'We'll have the runner try this 10000 times
steps_behind = 0 'runner starts at the bottom
seconds = 0 'reset time taken
stairs_length = 100 'Staircase has 100 steps
While steps_behind < stairs_length 'if the runner hasn't reached the top
steps_behind += 1 'go up one step
For j = 1 To 5 'The evil wizard conjures another five steps
If Int(Rnd * stairs_length) < steps_behind Then steps_behind += 1
'there's a chance that a new step will be behind you
stairs_length += 1 'but either way the staircase is one step longer
Next
seconds += 1 'that all took one second
If trial = 1 And seconds > 599 And seconds < 610 Then Print seconds, steps_behind, Chr$(9); stairs_length - steps_behind
'for the first attempt, see how the runner is doing after ten minutes
Wend
seconds_tot += seconds 'if the runner escaped, track the time taken and the length of the stairs
steps_tot += stairs_length
Next
Print "Average time taken: "; seconds_tot / 10000; " seconds."
Print "Average final staircase length: "; steps_tot / 10000; " steps."
'if you noticed that last number is about 100*exp(5), that's no coincidence
End </syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
 
==={{header|GW-BASIC}}===
Line 286 ⟶ 321:
190 PRINT TIMET/10000
200 PRINT STEPST/10000</syntaxhighlight>
 
==={{header|PureBasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="purebasic">OpenConsole()
Define.i steps_behind = 0, stairs_length = 100, seconds, j
Define.i seconds_tot, steps_tot
PrintN("Seconds" + #TAB$ + "steps behind" + #TAB$ + "steps ahead")
For trial.i = 1 To 10000 ;We'll have the runner try this 10000 times
steps_behind = 0 ;runner starts at the bottom
seconds = 0 ;reset time taken
stairs_length = 100 ;Staircase has 100 steps
While steps_behind < stairs_length ;if the runner hasn;t reached the top
steps_behind + 1 ;go up one step
For j = 1 To 5 ;The evil wizard conjures another five steps
If Int(Random(1) * stairs_length) < steps_behind:
steps_behind + 1
EndIf
;there;s a chance that a new step will be behind you
stairs_length + 1 ;but either way the staircase is one step longer
Next j
seconds + 1 ;that all took one second
If (trial = 1) And (seconds > 599) And (seconds < 610):
PrintN(Str(seconds) + #TAB$ + #TAB$ + Str(steps_behind) + #TAB$ + Str(stairs_length - steps_behind))
;for the first attempt, see how the runner is doing after ten minutes
EndIf
Wend
seconds_tot + seconds ;if the runner escaped, track the time taken and the length of the stairs
steps_tot + stairs_length
Next trial
 
PrintN("Average time taken: " + Str(seconds_tot/10000) + " seconds.")
PrintN("Average final staircase length: " + Str(steps_tot/10000) + " steps.")
;if you noticed that last number is about 100*exp(5), that;s no coincidence
 
PrintN(#CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()</syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
 
==={{header|QBasic}}===
2,136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.