Dice game probabilities: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) m →tbd: fixed for classic Rexx |
→{{header|J}}: formatting |
||
Line 156:
=={{header|J}}==
'''Solution:'''
<lang J>▼
<lang
'C0 P0' =. gen_dict/ x
'C1 P1' =. gen_dict/ y
(C0 +/@:,@:(>/&:({."1) * */&:({:"1)) C1) % (P0 * P1)
'''Example Usage:'''
<lang J> 10 5 (;x:inv)@:beating_probability 7 6
┌─────────────────────┬────────┐
│3781171969r5882450000│0.642789│
Line 172:
┌─────────────────┬────────┐
│48679795r84934656│0.573144│
└─────────────────┴────────┘</lang>
gen_dict explanation:<br>
<code>gen_dict</code> is akin to <code>gen_dict</code> in the python solution and
returns a table and total number of combinations, order matters.
The table has 2 columns. The first column is the pip count on all dice,
the second column is the number of ways this many pips can occur.
<code>({. , #)/.~
<code>,</code> raveled data (a vector) made of<br>▼
<code>+/&></code> the sum of each of the<br>▼
▲, raveled data (a vector)<br>
<code>(# <@:>:@:i.)</code> equi-probable die values<br>▼
▲+/&> the sum of each<br>
<code>&x:</code> but first use extended integers<br>▼
▲(# <@:>:@:i.) equi-probable die values<br>
▲&x: but first use extended integers<br>
▲<nowiki>; ^</nowiki> links the total possibilities to the result.
The verb <code>beating_probability</code> is akin to the python solution function having same name.<br>
<code>C0 >/&:({."1) C1</code> is a binary table where the pips of first player exceed pips of second player. "Make a greater than table but first take the head of each item."<br>
<code>C0 */&:({:"1) C1</code> is the corresponding table of occurrences<br>
<code>*</code> naturally we multiply the two tables (atom by atom, not a matrix product)<br>
<code>+/@:,@:
<code>% (P0 * P1)</code> after which divide by the all possible rolls.
=={{header|Java}}==
|