Two bullet roulette: Difference between revisions

m
→‎{{header|REXX}}: optimized execution which yields around 30% speed improvement.
m (→‎{{header|REXX}}: optimized execution which yields around 30% speed improvement.)
Line 1,003:
if tests=='' | tests=="," then tests= 100000 /* " " " " " " */
if datatype(seed, 'W') then call random ,,seed /* " " " " " " */
cyls_ = cyls - 1; @0= copies(0, cyls) /*shortcut placeholder for cylinders-1 */
@abc= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*indices for the various options used.*/
scenarios= 'LsLsFsFLSLSFsF LsLsFFLSLSFF LLsFsFLLSFSF LLsFFLLSFF' /*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. */
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*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
fire: != left(@, 1); @= callright(@, nextcyls_)left(@, 1); /* ◄──── next cyl.*/ return !
load: if left(@, 1) then @= callright(@, nextcyls_)left(@, 1); @= 1 || right(@, cyls_); return
next: @= right(@, cyls_)left(@, 1); return
spin: ?= random(1, cyls); if ?\==cyls then @= substr(@ || @, ? + 1, cyls); return
/*──────────────────────────────────────────────────────────────────────────────────────*/
method: @= copies(@0, cyls); do a=1 for length(q); y= substr(q, a, 1); upper y
if y=='L' then call load
else if y=='S' then call spin
else if y=='F' then if fire() then return 1
end /*a*/; end /*a*/; return 0
/*──────────────────────────────────────────────────────────────────────────────────────*/
act: $=; do a=1 for length(q); y= substr(q, a, 1); upper y
if y=='L' then $= $", load"
if y=='S' then $= $", spin"
if y=='F' then $= $", fire"
end /*a*/; 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:}}
<pre>