4
$\begingroup$

I'm trying to determine a formulation for the expected number of rounds for a game of chance based on dice.

The details of the game are as follows:

  1. The game initially consists of $N$ players

  2. Each player has a fair die or access to one.

  3. For each round each player will roll their die once

  4. The mean of the rolls is determined

  5. Any player that rolled a value less than the mean is eliminated from the game

  6. The rounds are repeated until their is only player left.

My question is how does one determined the expected number of round in terms of $N$.

My thinking is that for any round the expectation is that half of the players will be eliminated. This leads to a continuous halving of the number of players, which seems to suggest that $\text{E}(\text{Rounds}) \approx \log_2 {N}$, or specifically:

$$ \lim_{N \to \infty} \text{E}(\text{Rounds}) =\log_2 {N} $$

I wasn't able to formulate a definitive relation, so I ran a simple monte-carlo of the game, for numbers of players ranging from 2 players to 200 players, one million simulations per game size. The results can be found here:

https://gist.github.com/anonymous/f0db85f06343070045b78f7494f19565

The graph for the results and $\log_2 {N}$ is shown in the following as red and blue respectively:

http://i.imgur.com/KvJxNJb.png

Where I'm having difficulty is explaining the continuous and consistent over-estimate of the result curve (via simulation) when compared to the $\log_2{N}$ curve.

  • 0
    What happens to the players who throw exactly the average?2017-01-02
  • 1
    @FabioSomenzi as per point 5, only those who rolled less than the mean will be eliminated, all others will play the next round. That is to say players who rolled greater than or equal to the mean are not eliminated.2017-01-02
  • 0
    But you are assuming that half the players throw below average, while the other half throw at or above the average. Consider two players who both throw a four. The split is not 50/50. Am I missing something?2017-01-02
  • 1
    @FabioSomenzi in the 2 players each rolling 4 scenario, nothing happens another round is played. As another example say there are 10 players, 9 roll a 1 and the remaining rolls a 2. The mean is 1.1 all 9 players that rolled are eliminated leaving only one player as the winner.2017-01-02
  • 0
    I get it. What I'm trying to say is that halving the number of players at each round presupposes a symmetry that isn't there. Your example event is matched by the one in which 9 roll a 2 and the remaining one rolls a 1. The event in which all roll a 2 and survive has no counterpart.2017-01-02
  • 0
    I totally agree with the point that there's no permutation to counter. And that's where I'm having difficulty formulating an algebraic relation. By using Monte-Carlo I noticed that it tracked $log_2(N)$, in fact for any even number optioned game (coin-flip 2n-sided die etc) it seems to follow with error the $log_2(N)$ curve, now this could all just be coincidence.2017-01-02

2 Answers 2

3

Let e(n) be the expected number of rounds, starting with n players.

For a given positive integer n, the exact value of e(n) can be found via a recursive procedure.

I implemented such a procedure in Maple, and the results, for $2 \le n \le 8$, are shown below (the fractions are the exact values).

\begin{align*} e(2) &= \dfrac {6} {5} \approx 1.200000000\\ e(3) &= \dfrac {303} {175} \approx 1.731428571\\ e(4) &= \dfrac {81486} {37625} \approx 2.165740864\\ e(5) &= \dfrac {654386} {263375} \approx 2.484616991\\ e(6) &= \dfrac {1123369554} {409548125} \approx 2.742948839\\ e(7) &= \dfrac {1155681595606} {389948321875} \approx 2.963678854\\ e(8) &= \dfrac {49218033279086166} {15594311926296875} \approx 3.156152930 \end{align*}

Here's my Maple implementation of e(n) ...

enter image description here

  • 0
    when you say recursive do you mean that: $e(n) = e(n-1)+'some operations'$ or some other form.... If so could you please further elaborate, as your numbers seem to correspond to the numbers I get in simulation - I'd very much like an algebraic expression if that is at all possible.2017-01-03
  • 0
    It's an algorithm, not a formula.2017-01-03
  • 0
    Could you for example describe how $e(4)$ is determined to be $\dfrac {81486} {37625}$ ?2017-01-03
  • 1
    Is it Ok to post Maple code? It's about a page of code.2017-01-03
  • 1
    Of course! :D Anything to provide more explanations. I'm more than happy to read it, I used C++ myself,2017-01-03
  • 1
    Sorry it took so long. I tried various ways to include the program listing as text, but all my attempts failed badly, since MathJax did not retain any of the lines breaks. I finally gave up on that approach, and decided to simply post an image. If there are any questions about the program, feel free to ask.2017-01-03
  • 0
    I understand most of the code except for the if statement in the middle. Why do you continue onto the next loop from that point?2017-01-03
  • 1
    To avoid considering the case where all rolls are equal. That case is handled separately by two parts of the code. The first part is the initialization of e1. The second part is the factor by which e1 is scaled at the end.2017-01-03
  • 0
    I've pasted your code to gist, makes it easier for others to use: https://gist.github.com/anonymous/d59f355084d19c91624ba431c5ca7d082017-01-03
  • 0
    @quasi What's the largest $n$ that your program can process in, say, a minute? (As for including code in a post, you need to indent each line by an extra four spaces.)2017-01-03
  • 1
    @Pablo Somenzi: My Maple program can compute e(23) in 50 seconds. But I built it for ease of development (i.e., it was "built for comfort, not for speed"). I'm sure if I chose to, I could find ways to improve the efficiency of the algorithm. Also, if I switched the implementation language from Maple to Python or C, then, based on prior experience with various test programs, I would expect a speedup by a factor of 3 if I used Python, and a speedup by a factor of 200 if I used C.2017-01-04
  • 0
    Perhaps a memoization of 'e(m)' in the loop would help a great deal.2017-01-04
  • 0
    btw, just did a Monte-Carlo with 10e6 sims for e(23) took 14.6sec on a 3Ghz i7 with a result of 4.66700680 which is correct to 3 decimal places when compared to the Maple version. Though I still prefer the Maple version, just trying to now figure out how to get it implemented in C++2017-01-04
  • 0
    In the Maple implementation of e(n), note the statement "option remember". That statement tells Maple to store reviously computed input/output pairs, and to simply return a "remembered" output value when the input matches a previous input. In other words, with the "option remember" statement, memoization is _automatic_.2017-01-04
  • 1
    @quasi Thanks. Only saw your comment now, because you changed my name. I was asking before embarking in a programming exercise, but then I did anyway and wrote a C++ program based on the GMP bignum library. It gets to e(100) in about 10 minutes. I'm now running the program with a limit of 200, but it has only reached 106 and may take a very long time to terminate.2017-01-04
  • 0
    @Fabio Somenzi -- sorry about the "name change" (my eyes are bad).2017-01-05
  • 0
    @Fabio Somenzi -- I posted my Maple code as an image, rather than text, since I couldn't figure out how to get MathJax to show the program listing "verbatim". You mentioned "As for including code in a post, you need to indent each line by an extra four spaces." Can you give a link to some MSE post which has a text-based program listing?2017-01-05
  • 0
    @quasi You can look at the answer I posted. Instead of indenting all lines, it's actually easier to use the `code` and `pre` tags as I did.2017-01-05
1

I've run a C++ program very close in algorithm to the Maple program by @quasi. That is, it's based on

$$ e(n) = \frac{1+\sum_{0 < k < n}p_{k,n}\cdot e(k)}{1-p_{n,n}}\enspace,$$

where $p_{k,n}$ is the probability of there being $k$ survivors out of $n$ players.

Here's a snippet of the code, which shows how one works with the C++ bindings of the GMP bignum library.

static void print_expected_survivors(std::vector const & counts,
                                     long i, mpz_class outcomes)
{
  mpq_class exp_surv = 0;
  for (long j = 0; j != i; ++j) {
    exp_surv += counts[j] * (j+1);
  }
  exp_surv /= outcomes;
  mpf_class ef = exp_surv;
  std::cout << "s(" << i << ") = " << ef << std::endl;
}
In the GMP library, mpz, mpq, and mpf stand for multiple precision integer, rational, and floating-point number, respectively. This little function manipulates data of all three types as well as of type long.

Here's a plot of $e(n) - \log_2(n)$:

enter image description here

Not obvious from the data whether there is a horizontal asymptote different from $y=0$.

  • 0
    Is $p_{n,k}$ the binomial experiment of ${k}$ successes given $B(n,1/6)$?2017-01-05
  • 0
    btw, would you happen to know why there's a volatility at the start of the graph?2017-01-05
  • 0
    @JacobiJohn $p_{k,n}$ is the number of outcomes resulting in $k$ players with a score above average ($k$ survivors) divided by $6^n$. It is computed by going through all the 6-part *weak compositions* of $n$, computing the number of survivors--let it be $k$--and adding the multinomial coefficient corresponding to that composition to the count of outcomes with $k$ survivors. I believe the "volatility" is just the effect of quantization, which is more pronounced when the numbers are small.2017-01-06
  • 0
    @JacobiJohn correction: $p_{k,n}$ is the number of outcomes in which $k$ players have scores *greater than or equal* to the average divided by $6^n$.2017-01-06
  • 0
    Do you compute $p_{k,n}$ algebraically or algorithmically? The only way I can think of doing it is to enumerate each permutation of 6^n calculate the mean for each permutation, count how many are equal to or greater than the mean as k, then increment a 2D array of ints such as p[n,k] - if that's what you're doing I can't see how this is feasible with computers today beyond N of 15... :D2017-01-06
  • 0
    You are right that the exponential enumeration of all $6^n$ outcomes is hard to push past $n=15$ or thereabout. I enumerate the $(n+5$ choose $5)$ weak compositions of $n$ that have six parts, which is still terrible, but at least is polynomial. "Weak" means that some of the six parts may be 0. The meaning of "composition" can be found on Wikipedia under "composition (combinatorics)."2017-01-06