Function Repository Resource:

CompareDice

Source Notebook

Given two dice, calculate the odds that the first will win, tie or lose

Contributed by: Ed Pegg Jr

ResourceFunction["CompareDice"][a, b]

calculate the odds that die a will {win, tie, lose} to die b.

Examples

Basic Examples (1) 

A 4-sided die has a 1/4 chance of rolling higher than a 6-sided die:

In[1]:=
ResourceFunction["CompareDice"][{1, 2, 3, 4}, {1, 2, 3, 4, 5, 6}]
Out[1]=

Scope (4) 

In these intransitive dice, a>b>c>a:

In[2]:=
{a, b, c} = {{2, 2, 4, 4, 9, 9}, {1, 1, 6, 6, 8, 8}, {3, 3, 5, 5, 7, 7}};
{ResourceFunction["CompareDice"][a, b], ResourceFunction["CompareDice"][b, c], ResourceFunction["CompareDice"][c, a]}
Out[3]=

In Efron's dice, a>b>c>d>a:

In[4]:=
{a, b, c, d} = {{7, 7, 7, 7, 1, 1}, {5, 5, 5, 5, 5, 5}, {9, 9, 3, 3, 3, 3}, {8, 8, 8, 2, 2, 2}};
{ResourceFunction["CompareDice"][a, b], ResourceFunction["CompareDice"][b, c], ResourceFunction["CompareDice"][c, d], ResourceFunction["CompareDice"][d, a]}
Out[5]=

With Miwin's dice, a>b>c>a:

In[6]:=
{a, b, c} = {{1, 2, 5, 6, 7, 9}, {1, 3, 4, 5, 8, 9}, {2, 3, 4, 6, 7, 8}};
{ResourceFunction["CompareDice"][a, b], ResourceFunction["CompareDice"][b, c], ResourceFunction["CompareDice"][c, a]}
Out[7]=

A new set of intransitive dice:

In[8]:=
{a, b, c, d} = {{2, 3, 14, 15}, {1, 8, 12, 13}, {6, 7, 10, 11}, {4, 5, 9, 16}};
{ResourceFunction["CompareDice"][a, b], ResourceFunction["CompareDice"][b, c], ResourceFunction["CompareDice"][c, d], ResourceFunction["CompareDice"][d, a]}
Out[9]=

Neat Examples (2) 

Any two of Eric Harshbarger's "Go First Dice" have equal odds of winning:

In[10]:=
gofirst = {{1, 8, 11, 14, 19, 22, 27, 30, 35, 38, 41, 48},
   {2, 7, 10, 15, 18, 23, 26, 31, 34, 39, 42, 47},
   {3, 6, 12, 13, 17, 24, 25, 32, 36, 37, 43, 46},
   {4, 5, 9, 16, 20, 21, 28, 29, 33, 40, 44, 45}};
ResourceFunction["CompareDice"] @@ # & /@ Subsets[gofirst, {2}]
Out[11]=

In this set of fooling dice, a>b>c>d>e>a:

In[12]:=
{a, b, c, d, e} = {{6, 8, 11, 17}, {3, 4, 16, 19}, {2, 7, 15, 18}, {5, 10, 13, 14}, {1, 9, 12, 20}};
{ResourceFunction["CompareDice"][a, b], ResourceFunction["CompareDice"][b, c], ResourceFunction["CompareDice"][c, d], ResourceFunction["CompareDice"][d, e], ResourceFunction["CompareDice"][e, a]}
Out[13]=

However, if pairs of the dice are rolled, a<b<c<d<e<a:

In[14]:=
{ResourceFunction["CompareDice"][Total /@ Tuples[{a, a}], Total /@ Tuples[{b, b}]], ResourceFunction["CompareDice"][Total /@ Tuples[{b, b}], Total /@ Tuples[{c, c}]], ResourceFunction["CompareDice"][Total /@ Tuples[{c, c}], Total /@ Tuples[{d, d}]],
 ResourceFunction["CompareDice"][Total /@ Tuples[{d, d}], Total /@ Tuples[{e, e}]],
 ResourceFunction["CompareDice"][Total /@ Tuples[{e, e}], Total /@ Tuples[{a, a}]]}
Out[14]=

Version History

  • 1.0.0 – 08 December 2022

Related Resources

License Information