Two bullet roulette: Difference between revisions

Content added Content deleted
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
Line 453: Line 453:
=={{header|EasyLang}}==
=={{header|EasyLang}}==
{{trans|C}}
{{trans|C}}
<syntaxhighlight lang="text">len cyl[] 6
<syntaxhighlight lang="text">
len cyl[] 6
func rshift . .
func rshift . .
h = cyl[5]
h = cyl[6]
for i = 5 downto 1
for i = 6 downto 2
cyl[i] = cyl[i - 1]
cyl[i] = cyl[i - 1]
.
.
cyl[0] = h
cyl[1] = h
.
.
func unload . .
func unload . .
for i range 6
for i = 1 to 6
cyl[i] = 0
cyl[i] = 0
.
.
.
.
func load . .
func load . .
while cyl[0] = 1
while cyl[1] = 1
call rshift
call rshift
.
.
cyl[0] = 1
cyl[1] = 1
call rshift
call rshift
.
.
func spin . .
func spin . .
lim = random 6 + 1
lim = random 6
for i = 1 to lim - 1
for i = 1 to lim - 1
call rshift
call rshift
Line 480: Line 481:
.
.
func fire . shot .
func fire . shot .
shot = cyl[0]
shot = cyl[1]
call rshift
call rshift
.
.
Line 487: Line 488:
shot = 0
shot = 0
for m in m[]
for m in m[]
if m = 0
if m = 1
call load
call load
elif m = 1
elif m = 2
call spin
call spin
elif m = 2
elif m = 3
call fire shot
call fire shot
if shot = 1
if shot = 1
Line 502: Line 503:
func test m[] . .
func test m[] . .
n = 100000
n = 100000
for i range n
for i = 1 to n
call method m[] shot
call method m[] shot
sum += shot
sum += shot
.
.
for m in m[]
for i = 1 to len m[]
write method$[m] & " "
write method$[m[i]] & " "
.
.
print "-> " & 100 * sum / n & "% deaths"
print "-> " & 100 * sum / n & "% death"
.
.
call test [ 0 1 0 1 2 1 2 ]
call test [ 1 2 1 2 3 2 3 ]
call test [ 0 1 0 1 2 2 ]
call test [ 1 2 1 2 3 3 ]
call test [ 0 0 1 2 1 2 ]
call test [ 1 1 2 3 2 3 ]
call test [ 0 0 1 2 2 ]</syntaxhighlight>
call test [ 1 1 2 3 3 ]
</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==