Is this a valid simulation of this minesweeper-related question?

52 Views Asked by At

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$