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) |
do m=1 for #; q= word(scenarios, m) /*test each of the scenarios specified.*/ |
||
sum= 0 /*initialize the sum to zero. */ |
|||
sum = 0 |
|||
do tests; sum= sum + method() /*added the sums up for the percentages*/ |
|||
end /*tests*/ |
|||
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: |
method: @= copies(0, cyls); do a=1 for length(q); y= substr(q, a, 1); upper y |
||
if y=='L' then call load |
|||
if |
if y=='S' then call spin |
||
if |
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 |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
act: $=; do a=1 for length(q); y= substr(q, a, 1); upper y |
|||
if |
if y=='L' then $= $", load" |
||
if |
if y=='S' then $= $", spin" |
||
if |
if y=='F' then $= $", fire" |
||
end /*j*/; return right( strip( strip($, , ",") ), |
end /*j*/; return right( strip( strip($, , ",") ), 45)</lang> |
||
{{out|output|text= when using the default inputs, showing that 2<sup>nd</sup> option '''B''' has the highest probability for a suicide:}} |
{{out|output|text= when using the default inputs, showing that 2<sup>nd</sup> option '''B''' has the highest probability for a suicide:}} |
||
<pre> |
<pre> |
||
load, spin, load, spin, fire, spin, fire (option A) produces 55.44% deaths. |
|||
load, spin, load, spin, fire, fire (option B) produces 58.487% deaths. |
|||
load, load, spin, fire, spin, fire (option C) produces 55.82% deaths. |
|||
load, load, spin, fire, fire (option D) produces 50.021% deaths. |
|||
</pre> |
</pre> |
||