top | item 30318263

(no title)

sin7 | 4 years ago

    runs <- 10000
    x <- vector(mode = "numeric", length = runs)
    for (i in 1:runs){
      while (sum(sample(1:6, size = 3, replace = TRUE)) != 18){
        x[i] <- x[i] + 1
      }
    }

    summary(x)
    quantile(x, c(0.5, 0.8, 0.9)) 

    > summary(x)
       Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
        0.0    62.0   149.0   216.2   300.0  1902.0
    > quantile(x, c(0.5, 0.8, 0.9))
    50% 80% 90%
    149 350 495
A simple simulation. Run 10K times. Count the number of times it takes for three dice to add up 18.

The numbers very much agree with you. The median is 149. The 90th is 495 in the simulation, which is close enough to 496. There is very much a long tail in the data. So, the median and the average will not be the same. Is it a coincidence that mean is a 216?

discuss

order

randomswede|4 years ago

Off the top of my head, I don't know. It MAY be related to the fact that 6*3 is 216, but I don't have deep enough statistics knowledge to say for sure. You coudl try it again with 3 8-sided dice and rolling 24, that should give you ~50% at 344 iterations, and ~90% at 1177 iterations. If my supposition that the mean is related to the possible rolls, then the mean should end up being 512.

Iteration counts gathered with Python and a (manual) binary search (actually faster than writing code).

sin7|4 years ago

    runs <- 100000
    x <- vector(mode = "numeric", length = runs)
    for (i in 1:runs){
      while (sum(sample(1:8, size = 3, replace = TRUE)) != 24){
        x[i] <- x[i] + 1
      }
    }

    summary(x)
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
      0.0   146.0   353.0   511.8   708.0  5112.0 

    quantile(x, c(0.5, 0.8, 0.9))
     50%  80%  90% 
     353  824 1187
Strangely enough the mean agrees. The other ntiles are off a bit, but that's randomness for you.