Minesweeper thermodynamics

You know how sometimes you start a game of Minesweeper and immediately get stuck?

Like maybe there are some cells that you know are mines, but there aren’t any places that are safe to click.

In this example there are five different ways you could fill in the mines in the neighbouring cells. Note that there’s no cell which is safe in every possibility, so there’s nowhere we can safely click to get more information.

So in order to plan our next click, it would be good to know how likely it is that each cell is safe. You might think that each of the five possibilities is equally likely, in which case the probability that a cell is safe would be the proportion of them in which it isn’t a mine:

But it’s important to notice that the five possible arrangements have different numbers of mines. One has $5$ mines, three have $6$ and the last has $7$ (in addition to the $5$ mines we already found).

Let’s say for example that we’re playing the ‘expert’ version of Minesweeper: a $30\times 16$ board with $99$ mines. That means that outside the solved region there are $444$ remaining cells and $94$ remaining mines. So for each possibility the total number of ways to arrange the mines in the rest of the board is one of the following.$$\binom{444}{94-5}=1.930\times 10^{95}$$ $$\binom{444}{94-6}=0.483\times 10^{95}$$ $$\binom{444}{94-7}=0.119\times 10^{95}$$

Different versions of Minesweeper randomise the mines slightly differently, but after your first click it’s a good approximation that every possibility is equally likely. So the possibility with only $5$ mines is about $16.2$ times as likely as the possibility with $7$ mines!

This means we should calculate how safe each cell is by finding the proportion of the possibilities in which it’s safe, but weighted by the above numbers. That gives us the following probabilities:

Previously we thought that the six best cells each had a $40\%$ chance of safety. Now we see that some of them have a $69.0\%$ chance of safety, and some of them only have $17.2\%$!


In statistical mechanics, the Boltzmann distribution is a law that tells you how likely a physical system is to be in a particular state. It works in the context that your system is in equilibrium with a larger environment that acts as a ‘heat bath’, holding it at a particular temperature $T$. Each of the states of your system has some amount of energy $E$, and Boltzmann’s formula says that the probability to find it in a given state is proportional to$$\exp\left(-\frac{E}{kT}\right)$$where $k$ is Boltzmann’s constant.

Ising Model (from Wikipedia)

A typical application might be something like a grid of atoms that can each be in either an excited or unexcited state. The Boltzmann distribution lets us calculate how many atoms are excited. But I want to apply it to Minesweeper.

The idea is that our little corner of the Minesweeper grid is like a physical system within a larger environment; a ‘mine bath’. The probability of the corner being in each possible state is determined by the number of mines, which we want to treat like the energy.

Above we saw that the probability of a possibility with $m$ mines is proportional to$$\binom{C}{M-m}$$where there are $C$ cells and $M$ mines remaining. In order to make our analogy precise, we would have to express this in a form matching Boltzmann’s law,$$\binom{C}{M-m}\propto\exp\left(-\frac{m}{T}\right)$$where $T$ is some sort of ‘mine temperature’ defined in terms of $C$ and $M$.

When we rewrite the binomial coefficient in terms of factorials, we get$$\frac{C!}{(M-m)!(C-M+m)!}.$$If we increase $m$ by $1$ then the $(M-m)!$ term will decrease by a factor of $M-m$ while the $(C-M+m)!$ term increases by a factor of $C-M+m+1$. So the overall probability will change by a factor of $(M-m)/(C-M+m+1)$.

At the start of the game the number of remaining mines is large compared to the number of mines that we’re worrying about at the boundary of the solved region. So $m$ is small compared to $M$ and $C$. So we can use the approximation $(M-m)/(C-M+m+1) \approx M/(C-M)$. This suggests that for small $m$ the probability of a possibility with $m$ mines is proportional to$$\left(\frac{M}{C-M}\right)^m.$$

This can then be rewritten in the form$$\exp\left(\frac{m}{1/\log\left(\frac{M}{C-M}\right)}\right).$$ So we can indeed pretend that Boltzmann’s law applies to this situation, with a ‘mine temperature’ of $1/\log\left(\frac{M}{C-M}\right)$.

How good is this approximation? Well in our case $M/(C-M) = 94/(444-94) = 0.269\dots$. So the possibility with $5$ mines would be $1/(0.269\dots)^2 = 13.86\dots$ times as likely as the possibility with $7$ mines. But we saw above that this ratio was actually about $16.2$. So it has the right order of magnitude, but it’s not a very accurate estimate.

Statistical physics is often applied to macroscopic physical systems, where the number of particles is in the region of Avogadro’s number. If Minesweeper’s expert mode had $6\times 10^{23}$ mines then our approximation would be much better!


Addendum: This post was discussed on Hacker News, Reddit, Mastodon and Lemmy.

Posted in Uncategorized | 10 Comments

3d Sudoku

Consider this $9\times 9\times 9$ grid, in which some cubes have been shaded.

3d-sudoku

It can be represented in two dimensions by viewing it from one side and using numbers from $1$ to $9$ to give the location of each cube in the into-the-page direction.

2d-sudoku

Challenge Add cubes to the above grid so that, no matter which side we look at, these numbers obey the rules of Sudoku. Continue reading

Posted in Uncategorized | 3 Comments

Unique Distancing Problem

The most recent of Matt Parker’s Maths Puzzles was the unique distancing problem:

For which $n\in\mathbb N$ is it possible to place $n$ counters on an $n\times n$ square grid so that there’s a different distance between each pair of distinct counters? (Distances are measured in the normal Pythagorean way, so if there is a counter at $(0,0)$ we cannot have counters at both $(5,0)$ and $(4,3)$).

For small $n$ the problem is not too hard. I managed to use a computer search to find solutions for $n<8$ and prove that there were no solutions for $8\leq n < 11$. For $n\geq 16$ it’s trivial that there are no solutions because the number of pairs of counters is greater than the number of distances possible on the grid. This leaves the cases $n = 11$, $12$, $13$, $14$ and $15$.

Fellow puzzler Gal Holowitz wrote code efficient enough to deal with four of these remaining cases, $n = 11$, $12$, $13$ and $14$, finding that there were no solutions for any of them. But for the $n=15$ case their code is still running!

So you would think that $n=15$ was the hardest case of all. But in fact you can prove that there are no solutions for this case by using just pen and paper. Here’s how. Continue reading

Posted in Uncategorized | 4 Comments

A better representation for real numbers

Real numbers can be represented by decimals or by continued fractions, but both of these systems have the problem that the representations are not unique. This nonuniqueness can introduce ugly complications into proofs that use these representations, in particular those regarding the cardinality of $\mathbb R$.

In this post I’ll explain what causes these complications, and then define a system that avoids them. In particular I’ll define an elegant and order-preserving bijection from the interval $[0,1)$ to the set $\mathbb N \to\mathbb N$ of sequences of natural numbers.

(In case this notation is unfamiliar to readers, the set $[x,y)$ contains all the real numbers from $x$ to $y$, including $x$ but not including $y$. The set $A\to B$ contains all functions from $A$ to $B$. Also, I use the convention that $\mathbb N$ contains $0$.)

Composition of reals seen as sequences

Continue reading

Posted in Uncategorized | 9 Comments

Dividing by a vector

There are various ways that we can multiply vectors.

  • We can multiply a vector by a scalar to get another vector: $w=\lambda v$.
  • We can multiply a vector by a linear map to get another vector: $w=\alpha v$.
  • We can dot-product two vectors to get a scalar: $\lambda = w\cdot v$.
  • We can cross-product two vectors to get another vector: $u = w\times v$.

If we wanted to divide by a vector we would need for one of these equations to have a unique inverse. Sadly this rarely happens.

  • Given $v$ and $w$ there’s no scalar $\lambda$ such that $w=\lambda v$, unless $v$ and $w$ happen to point in the same direction.
  • Given $v$ and $w$ there are typically many linear maps such that $w=\alpha v$. If $v\in V$ and $w\in W$ then the space of linear maps sending $v$ to $w$ has dimension $(\mathrm{dim}(V)-1)\mathrm{dim(W)}$.
  • Given $\lambda$ and $v$ there’s an entire hyperplane of solutions to $\lambda = w\cdot v$.
  • Given $u$ and $v$, there are no solutions to $u = w\times v$ unless $u$ and $v$ are perpendicular, in which case there is an entire line of solutions.

But there are some cases where you can divide by a vector. The case I want to look at today is the one where $V$ is $1$-dimensional. Continue reading

Posted in Uncategorized | Leave a comment

Adjunctions between monoids

In the last post, I talked about Monads on Monoids. We defined these by turning each monoid into a category (its delooping), and then looking at monads on this category. This data could then be reexpressed in terms of the original monoid.

We can also apply exactly the same process to define adjunctions between monoids. These were studied by Vladimir Molotkov in his paper ‘Adjunction in Monoids‘. Continue reading

Posted in Uncategorized | 2 Comments

Monads on monoids

This post is inspired by a couple of posts on math.stackexchange.com asking what a ‘monad on a monoid’ is.


In category theory there are a couple of especially simple kinds of category. For any partial order we can put a category structure on its elements by saying that there’s a unique morphism $x\to y$ if $x\leq y$ and none otherwise. And for any monoid we can construct a category with one object and with the morphisms from that object to itself being the elements the monoid.

These two examples are complementary to each other. With partial orders you can have as many objects as you want, but the morphisms have to be as simple as possible. Monoids are the opposite, you can only have one object but it can have as many morphisms as you like.

Sometime when we’re doing category theory it can help to think about these categories as a way of restricting our attention. If we have some complicated categorical construction then we can gain some intuition about it by looking at how it applies to these two simple cases. Today the ‘complicated categorical construction’ we’re interested in is monads. Continue reading

Posted in Uncategorized | 2 Comments