Source of this problem:
A: There are nine tetrahedral dice (each dice has four sides of 1,2,3,4)
B: There are 6 hexahedral dice (each dice has six faces, 1,2,3,4,5,6)
If two people roll dice, the one with the largest number wins.
What is the probability of A winning B?
I calculate the problem in the following way:
Clear["Global`*"]
A = Range[9, 36];
B = Range[6, 36];
data = Tuples[{1, 2, 3, 4}, 9(*Nine tetrahedral dice*)];(*Equal probability event*)
p1 = Evaluate[Array[tetrahedron, Length[A]]] =
Tally[Total /@ data][[All, 2]]/4^9;
data = Tuples[{1, 2, 3, 4, 5, 6},
6(*Six hexahedral dice*)];(*Equal probability event*)
p2 = Evaluate[Array[hexahedron, Length[B]]] =
Tally[Total /@ data][[All, 2]]/6^6;
s = Table[p2[[6 - 6 + 1 ;; 9 - 6 + i]], {i, 0, Length[A] - 1}];
Total[Table[Total[(p1[[i]]*s[[i]])], {i, 1, Length[A]}]]//N
(*Violence simulation results*)
Count[Table[If[Total[RandomInteger[{1, 4}, 9]] >
Total[RandomInteger[{1, 6}, 6]], 1, 0], 1000000], 1]/1000000.
In calculating this problem, I encountered some array operation problems. I extracted them and described them as follows:
First question
I've got two sets of data a and B (simulating nine tetrahedral and six hexahedral dice):
A = Range[9, 36]
B = Range[6, 36]
Now I want to get the set of elements in group B that are smaller than each element in group A one by one:
{9, {6, 7, 8}}
{10, {6, 7, 8, 9}}
{11, {6, 7, 8, 9, 10}}
...
{36, {6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35}}
What should I do to get the desired result? In addition, it is better to use a general method, because we need to consider two irregular arrays.
Second question
In addition, how to efficiently split an array step by step?
{1, 2, 4, 6, 8, 7, 9, 3}
I want to split the above array from position 2 to position 6 as follows:
{1, 2}
{1, 2, 4}
{1, 2, 4, 6}
{1, 2, 4, 6, 8}
{1, 2, 4, 6, 8, 7}