Two bullet roulette: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: optimized execution which yields around 30% speed improvement.) |
|||
Line 1,003: | Line 1,003: | ||
if tests=='' | tests=="," then tests= 100000 /* " " " " " " */ |
if tests=='' | tests=="," then tests= 100000 /* " " " " " " */ |
||
if datatype(seed, 'W') then call random ,,seed /* " " " " " " */ |
if datatype(seed, 'W') then call random ,,seed /* " " " " " " */ |
||
cyls_ = cyls - 1 |
cyls_ = cyls - 1; @0= copies(0, cyls) /*shortcut placeholder for cylinders-1 */ |
||
abc= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
@abc= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*indices for the various options used.*/ |
||
scenarios= ' |
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. */ |
|||
do tests; |
do tests; sum= sum + method() /*added the sums up for the percentages*/ |
||
end /*tests*/ |
end /*tests*/ |
||
pc= left( (sum * 100 / tests)"%", 7) |
pc= left( (sum * 100 / tests)"%", 7) |
||
say act() |
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. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
fire: != left(@, 1); |
fire: != left(@, 1); @= right(@, cyls_)left(@, 1); /* ◄──── next cyl.*/ return ! |
||
load: if left(@, 1) then |
load: if left(@, 1) then @= right(@, cyls_)left(@, 1); @= 1||right(@, cyls_); return |
||
next: @= right(@, cyls_)left(@, 1); return |
|||
spin: ?= random(1, cyls); if ?\==cyls then @= substr(@ || @, ? + 1, cyls); return |
spin: ?= random(1, cyls); if ?\==cyls then @= substr(@ || @, ? + 1, cyls); return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
method: @= |
method: @= @0; do a=1 for length(q); y= substr(q, a, 1) |
||
if y=='L' then call load |
|||
else if y=='S' then call spin |
|||
if y=='F' then if fire() then return 1 |
else if y=='F' then if fire() then return 1 |
||
end /*a*/; return 0 |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
act: $=; |
act: $=; do a=1 for length(q); y= substr(q, a, 1) |
||
if y=='L' then $= $", load" |
|||
if y=='S' then $= $", spin" |
|||
if y=='F' then $= $", fire" |
|||
end /*a*/; 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> |