0

The question: Probability of getting a $7$ in Minesweeper.

Description of what I tried to do:

  • Create empty $16 \times 30$ matrix
  • Pick random cells and set them to $1$ until the matrix has $99$ "mines"
  • For all remaining empty cells, inscribe the sum of the surrounding fields (but in a new empty matrix in the corresponding spots)
  • Count the occurrences of $7$
  • Do all of this lots of times (between $10^3$ and $5\cdot10^5$)
  • Take the average

Results for the $3$ highest iterations: $0.02756$, $0.02751$ and $0.02749$ which seems quite far away (from the result derived in the answer) for that amount of simulations. Also for some reason there are never more than 4 decimals, but lots of zeroes thereafter. Is my idea and/or execution faulty somewhere?

Code on pastebin. I am not a programmer, so please be kind $:p$

355durch113
  • 1,570
  • 1
    Sometimes your code can put mines on top of each other. Try running it multiple times to see how much variation you get - I think you will need many more trials for it to approach the actual probability. –  Jun 12 '16 at 20:33
  • @TokenToucan It does, but that should not be a problem for the randomness, right? It's always around 0.0275 instead of 0.02716. Currently running 5 million trials. – 355durch113 Jun 12 '16 at 22:02
  • With m = 5 million iterations you may be off by about 1 digit in the 4th decimal place: p = .0275, margin of simulation error 2*sqrt(p*(1-p)/m). – BruceET Jun 14 '16 at 19:24

0 Answers0