Two bullet roulette: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added a comment.)
m (→‎{{header|REXX}}: added which of the options had the highest percentage of deaths as per the task's requirement.)
Line 815: Line 815:
if datatype(seed, 'W') then call random ,,seed /* " " " " " " */
if datatype(seed, 'W') then call random ,,seed /* " " " " " " */
cyls_ = cyls - 1 /*shortcut placeholder for cylinders-1 */
cyls_ = cyls - 1 /*shortcut placeholder for cylinders-1 */
abc= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*indices for the various options used.*/
scenarios= 'LsLsFsF LsLsFF LLsFsF LLsFF' /*the list of scenarios to be tested. */
scenarios= 'LsLsFsF LsLsFF LLsFsF LLsFF' /*the list of scenarios to be tested. */
#= words(scenarios) /*the number of actions in a scenario. */
#= words(scenarios) /*the number of actions in a scenario. */
/*The scenarios are case insensitive. */
/*The scenarios are case insensitive. */
do m=1 for #; q= word(scenarios, m) /*test each of the scenarios specified.*/
do m=1 for #; q= word(scenarios, m) /*test each of the scenarios specified.*/
sum= 0 /*initialize the sum to zero. */
sum = 0
do t=1 for tests; sum= sum + method(q)
do tests; sum= sum + method() /*added the sums up for the percentages*/
end /*t*/
end /*tests*/
say action(q) ' produces ' left( (sum*100/tests)"%", 7) ' deaths.'
pc= left( (sum * 100 / tests)"%", 7)
say act() ' (option' substr(abc, m, 1)") produces " pc ' deaths.'
end /*m*/
end /*m*/
exit 0 /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
Line 831: Line 833:
spin: ?= random(1, cyls); if ?\==cyls then @= substr(@ || @, ? + 1, cyls); return
spin: ?= random(1, cyls); if ?\==cyls then @= substr(@ || @, ? + 1, cyls); return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
method: arg scenario; @= copies(0, cyls) /*start with an empty cartridge chamber*/
method: @= copies(0, cyls); do a=1 for length(q); y= substr(q, a, 1); upper y
do a=1 for length(scenario); act= substr(scenario, a, 1)
if y=='L' then call load
if act=='L' then call load
if y=='S' then call spin
if act=='S' then call spin
if y=='F' then if fire() then return 1
if act=='F' then if fire() then return 1
end /*a*/; return 0
end /*a*/; return 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
action: arg scenario,$; do a=1 for length(scenario); act= substr(scenario, a, 1)
act: $=; do a=1 for length(q); y= substr(q, a, 1); upper y
if act=='L' then $= $", load"
if y=='L' then $= $", load"
if act=='S' then $= $", spin"
if y=='S' then $= $", spin"
if act=='F' then $= $", fire"
if y=='F' then $= $", fire"
end /*j*/; return right( strip( strip($, , ",") ), 50)</lang>
end /*j*/; return right( strip( strip($, , ",") ), 45)</lang>
{{out|output|text=&nbsp; when using the default inputs, &nbsp; showing that 2<sup>nd</sup> option &nbsp; '''B''' &nbsp; has the highest probability for a suicide:}}
{{out|output|text=&nbsp; when using the default inputs, &nbsp; showing that 2<sup>nd</sup> option &nbsp; '''B''' &nbsp; has the highest probability for a suicide:}}
<pre>
<pre>
load, spin, load, spin, fire, spin, fire produces 55.44% deaths.
load, spin, load, spin, fire, spin, fire (option A) produces 55.44% deaths.
load, spin, load, spin, fire, fire produces 58.487% deaths.
load, spin, load, spin, fire, fire (option B) produces 58.487% deaths.
load, load, spin, fire, spin, fire produces 55.82% deaths.
load, load, spin, fire, spin, fire (option C) produces 55.82% deaths.
load, load, spin, fire, fire produces 50.021% deaths.
load, load, spin, fire, fire (option D) produces 50.021% deaths.
</pre>
</pre>