Long stairs: Difference between revisions

5,445 bytes added ,  2 months ago
Added various BASIC dialects(QBasic, BASIC256, Yabasic and True BASIC))
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Added various BASIC dialects(QBasic, BASIC256, Yabasic and True BASIC)))
Line 186:
Average time taken = 3063.260000 Sec
Average Stair length = 15416.300000 steps</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">steps_behind = 0
stairs_length = 100
seconds_tot = 0
steps_tot = 0
print "Seconds steps behind steps ahead"
for trial = 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(rand*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 j
seconds += 1 #that all took one second
if trial = 1 and seconds > 599 and seconds < 610 then print seconds, steps_behind, stairs_length - steps_behind
#for the first attempt, see how the runner is doing after ten minutes
end while
seconds_tot += seconds #if the runner escaped, track the time taken and the length of the stairs
steps_tot += stairs_length
next trial
 
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</syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{works with|True BASIC}}
<syntaxhighlight lang="qbasic">RANDOMIZE TIMER : REM RANDOMIZE for True BASIC
stepsbehind = 0
stairslength = 100
 
PRINT "Seconds", "steps behind", "steps ahead"
FOR trial = 1 TO 10000
stepsbehind = 0
seconds = 0
stairslength = 100
DO WHILE stepsbehind < stairslength
stepsbehind = stepsbehind + 1
FOR j = 1 TO 5
IF INT(RND * stairslength) < stepsbehind THEN stepsbehind = stepsbehind + 1
stairslength = stairslength + 1
NEXT j
seconds = seconds + 1
IF trial = 1 AND seconds > 599 AND seconds < 610 THEN PRINT seconds, stepsbehind, stairslength - stepsbehind
LOOP
secondstot = secondstot + seconds
stepstot = stepstot + stairslength
NEXT trial
 
PRINT "Average time taken: "; secondstot / 10000; " seconds."
PRINT "Average final staircase length: "; stepstot / 10000; " steps."
END</syntaxhighlight>
 
==={{header|True BASIC}}===
{{trans|QBasic}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">RANDOMIZE ! RANDOMIZE TIME for QBasic
LET stepsbehind = 0
LET stairslength = 100
 
PRINT "Seconds", "steps behind", "steps ahead"
FOR trial = 1 TO 10000
LET stepsbehind = 0
LET seconds = 0
LET stairslength = 100
DO WHILE stepsbehind < stairslength
LET stepsbehind = stepsbehind + 1
FOR j = 1 TO 5
IF INT(RND * stairslength) < stepsbehind THEN LET stepsbehind = stepsbehind + 1
LET stairslength = stairslength + 1
NEXT j
LET seconds = seconds + 1
IF trial = 1 AND seconds > 599 AND seconds < 610 THEN PRINT seconds, stepsbehind, stairslength - stepsbehind
LOOP
LET secondstot = secondstot + seconds
LET stepstot = stepstot + stairslength
NEXT trial
 
PRINT "Average time taken: "; secondstot / 10000; " seconds."
PRINT "Average final staircase length: "; stepstot / 10000; " steps."
END</syntaxhighlight>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">steps_behind = 0
stairs_length = 100
print "Seconds", chr$(9), "steps behind", chr$(9), "steps ahead"
for trial = 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 = steps_behind + 1 //go up one step
for j = 1 to 5 //The evil wizard conjures another five steps
if int(ran(1)*stairs_length) < steps_behind steps_behind = steps_behind + 1
//there//s a chance that a new step will be behind you
stairs_length = stairs_length + 1 //but either way the staircase is one step longer
next j
seconds = seconds + 1 //that all took one second
if trial = 1 and seconds > 599 and seconds < 610 print seconds, chr$(9), steps_behind, chr$(9), chr$(9), stairs_length - steps_behind
//for the first attempt, see how the runner is doing after ten minutes
wend
seconds_tot = seconds_tot + seconds //if the runner escaped, track the time taken and the length of the stairs
steps_tot = steps_tot + stairs_length
next trial
 
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</syntaxhighlight>
{{out}}
<pre>Similar as FreeBASIC entry.</pre>
 
=={{header|C}}==
2,131

edits