Two bullet roulette: Difference between revisions
Added 11l
m (→{{header|REXX}}: optimized execution which yields around 30% speed improvement.) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 45:
Youtube video on the Russian 1895 Nagant revolver [[https://www.youtube.com/watch?v=Dh1mojMaEtM]]
<br><br>
=={{header|11l}}==
{{trans|Go}}
<lang 11l>UInt32 seed = 0
F nonrandom(n)
:seed = 1664525 * :seed + 1013904223
R Int(:seed >> 16) % n
V cylinder = [0B] * 6
F rshift()
V t = :cylinder[5]
L(i) (4..0).step(-1)
:cylinder[i + 1] = :cylinder[i]
:cylinder[0] = t
F unload()
L(i) 6
:cylinder[i] = 0B
F load()
L :cylinder[0]
rshift()
:cylinder[0] = 1B
rshift()
F spin()
L(i) 1 .. nonrandom(6)
rshift()
F fire()
V shot = :cylinder[0]
rshift()
R shot
F method(s)
unload()
L(c) s
S c
‘L’
load()
‘S’
spin()
‘F’
I fire()
R 1
R 0
F mstring(s)
[String] l
L(c) s
S c
‘L’
l [+]= ‘load’
‘S’
l [+]= ‘spin’
‘F’
l [+]= ‘fire’
R l.join(‘, ’)
V tests = 100000
L(m) [‘LSLSFSF’, ‘LSLSFF’, ‘LLSFSF’, ‘LLSFF’]
V sum = 0
L 0 .< tests
sum += method(m)
V pc = Float(sum) * 100 / tests
print(‘#<40 produces #2.3% deaths.’.format(mstring(m), pc))</lang>
{{out}}
<pre>
load, spin, load, spin, fire, spin, fire produces 55.434% deaths.
load, spin, load, spin, fire, fire produces 58.373% deaths.
load, load, spin, fire, spin, fire produces 55.428% deaths.
load, load, spin, fire, fire produces 50.041% deaths.
</pre>
=={{header|C}}==
|