Two bullet roulette: Difference between revisions

m
→‎{{header|REXX}}: added which of the options had the highest percentage of deaths as per the task's requirement.
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:
if datatype(seed, 'W') then call random ,,seed /* " " " " " " */
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. */
#= words(scenarios) /*the number of actions in a scenario. */
/*The scenarios are case insensitive. */
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 + domethod() t=1 /*added forthe tests;sums up for sum=the sum + method(q)percentages*/
end /*ttests*/
say action(q) ' produces ' pc= left( (sum * 100 / tests)"%", 7) ' deaths.'
say act() ' (option' substr(abc, m, 1)") produces " pc ' deaths.'
end /*m*/
exit 0 /*stick a fork in it, we're all done. */
Line 831 ⟶ 833:
spin: ?= random(1, cyls); if ?\==cyls then @= substr(@ || @, ? + 1, cyls); return
/*──────────────────────────────────────────────────────────────────────────────────────*/
method: arg scenario; @= copies(0, cyls); do a=1 for /*startlength(q); with an empty cartridge chamber*/ y= substr(q, a, 1); upper y
doif ay=1='L' for length(scenario); act= substr(scenario,then a,call 1)load
if acty=='LS' then call loadspin
if acty=='SF' then callif spinfire() then return 1
if act=='F' then if fire() then return 1
end /*a*/; return 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
actionact: arg scenario, $=; do a=1 for length(scenarioq); act y= substr(scenarioq, a, 1); upper y
if acty=='L' then $= $", load"
if acty=='S' then $= $", spin"
if acty=='F' then $= $", fire"
end /*j*/; return right( strip( strip($, , ",") ), 5045)</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:}}
<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>