There is a game about coin collection. There are 5 coins with values 2,3,4,5,6. The player is given at max 6 chances to draw, each draw could result in one of the coins at the probability of 0.13, 0.18, 0.4, 0.14, 0.15 (possible to draw 2 or more coins of the same value). Each time the player reveals a coin, there is a chance to win that coin in the probability of 1/COIN VALUE. For example, if the player gets a COIN of value 3, there is 1/3 chance to win that coin. Each time the player collects a coin, the judge will check if the total value is more than or equal to 12, if yes, the player wins the game, otherwise, repeat it until 6 chances are used.

I am looking for a way to estimate the probability to win the game. I simply the problem as

1. find the average value of a coin to be revealed on each draw, which is $$V = 2\*0.13+3\*0.18+4\*0.40+5\*0.14+6\*0.15 = 4$$
2. the probability of winning the average coin (value=4) will be $P=1/4$
3. the criterion expects a value of 12 to be collected and thus average $12/V=3$ draws will be.
4. each draw is a Bernoulli process and thus the probability to win the game is the same as the probability of getting 3 or more success in 6 trails or
$$
P(6,3) + P(6,4) + P(6,5) + P(6,6)
$$
where $P(n,m)$ means the probability of exact m success out of n trials. I compute it and find out there is 16.94% to win the game.

However, I check the result with a piece of code and obtain a very different answer. Here is the pseudo-code

```
X <- 0 // how many time to win the game
for n -> 1 to 100000000 {
    T <- 0 // total coin value per set of draws
  for m -> 1 to 6 {
    C <- randomly pick a coin with the weight
    Q <- randomly pick the success probability
    P <- randomly pick from (0, 1) in uniform distribution
    if P<Q { // means collect the coin
      T <- T + C
    } 
    if T>12 {
      X <- X+1
      stop this game
    }
  }
}

print X/C 

```

here X/C should be the winning percentage and should be close to the probability of winning the game. But the program turns out that X/C is about 11% instead of 16.94%. It took me the whole day to check the code and the math, I don't see how it get wrong. Any clue to solve this problem is appreciated.