Jump to content

Two bullet roulette: Difference between revisions

→‎{{header|REXX}}: added the computer programming language REXX.
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 800:
 
Doesn't change the answers, B (LSLSFF) is definitely the <strike>worst</strike> most likely choice in all cases.
 
=={{header|REXX}}==
{{trans|GO}}
<lang rexx>/*REXX pgm simulates scenarios for a two─bullet Russian roulette game with a 6 cyl. gun.*/
parse arg cyls tests seed . /*obtain optional arguments from the CL*/
if cyls=='' | cyls=="," then cyls= 6 /*Not specified? Then use the default.*/
if tests=='' | tests=="," then tests= 100000 /* " " " " " " */
if datatype(seed, 'W') then call random ,,seed /* " " " " " " */
scenarios= 'LsLsFsF LsLsFF LLsFsF LLsFF' /*the list of scenarios to be tested. */
#= words(scenarios) /*the number of actions in a scenario. */
 
do m=1 for #; q= word(scenarios, m) /*test each of the scenarios specified.*/
sum = 0
do t=1 for tests; sum= sum + method(q)
end /*t*/
 
say action(q) ' produces ' left( (sum*100/tests)"%", 7) ' deaths.'
end /*m*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fire: != @.1; call next; return !
load: do @.1; call next; end; @.1= 1 /*load cyl 1*/; return
next: do j=1 for cyls; p= j - 1; @.p= @.j; end; @.cyls= @.0; return
spin: ?= random(1, cyls); if ?\==6 then do ?; call next; end; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
method: arg scenario; @.= 0; do a=1 for length(scenario); act= substr(scenario, a, 1)
if act=='L' then call load
if act=='S' then call spin
if act=='F' then if fire() then return 1
end /*a*/; return 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
action: arg scenario,$; do a=1 for length(scenario); act= substr(scenario, a, 1)
if act=='L' then $= $", load"
if act=='S' then $= $", spin"
if act=='F' then $= $", fire"
end /*j*/; return right( strip( strip($, , ",") ), 50)</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
output
<pre>
load, spin, load, spin, fire, spin, fire produces 55.44% deaths.
load, spin, load, spin, fire, fire produces 58.487% deaths.
load, load, spin, fire, spin, fire produces 55.82% deaths.
load, load, spin, fire, fire produces 50.021% deaths.
</pre>
 
=={{header|Wren}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.