Two bullet roulette: Difference between revisions

Content added Content deleted
Line 469: Line 469:
proc load . .
proc load . .
while cyl[1] = 1
while cyl[1] = 1
call rshift
rshift
.
.
cyl[1] = 1
cyl[1] = 1
call rshift
rshift
.
.
proc spin . .
proc spin . .
lim = random 6
lim = random 6
for i = 1 to lim - 1
for i = 1 to lim - 1
call rshift
rshift
.
.
.
.
proc fire . shot .
func fire .
shot = cyl[1]
shot = cyl[1]
call rshift
rshift
return shot
.
.
proc method m[] . shot .
func method m[] .
call unload
unload
shot = 0
for m in m[]
for m in m[]
if m = 1
if m = 1
call load
load
elif m = 2
elif m = 2
call spin
spin
elif m = 3
elif m = 3
call fire shot
if fire = 1
if shot = 1
return 1
break 1
.
.
.
.
.
.
return 0
.
.
method$[] = [ "load" "spin" "fire" ]
method$[] = [ "load" "spin" "fire" ]
Line 504: Line 504:
n = 100000
n = 100000
for i = 1 to n
for i = 1 to n
call method m[] shot
sum += method m[]
sum += shot
.
.
for i = 1 to len m[]
for i = 1 to len m[]
Line 512: Line 511:
print "-> " & 100 * sum / n & "% death"
print "-> " & 100 * sum / n & "% death"
.
.
call test [ 1 2 1 2 3 2 3 ]
test [ 1 2 1 2 3 2 3 ]
call test [ 1 2 1 2 3 3 ]
test [ 1 2 1 2 3 3 ]
call test [ 1 1 2 3 2 3 ]
test [ 1 1 2 3 2 3 ]
call test [ 1 1 2 3 3 ]
test [ 1 1 2 3 3 ]
</syntaxhighlight>
</syntaxhighlight>