Ponder This Challenge - February 2026 - Blot-avoiding backgammon strategy
- Ponder This
We deal with mazes which are composed of an grid of rectangular cells, where each cell is connected to its four direct neighbors. For each pair of neighbors, either there is a wall between them or not. The maze is constructed in such a manner such that for every two cells in the maze, there is excactly one path between them - in particular, one path from the beginning to the end.
Under these constraints, it can be seen there are exactly 192 mazes of size (we count mazes as distinct even if they are the same up to rotation/reflection). The number of mazes grow exponentially with length; for a size of as in the picture, the number of mazes is already , which can be stylized as "1.289e66"
Your goal: Find the number of mazes. Give your result styled as above, in the form of a floating-point number with four digits of precision followed by an exact exponent.
A Bonus "*" will be given for finding the number of mazes. Give your result in the same format as above.
We will post the names of those who submit a correct, original solution! If you don't want your name posted then please include such a statement in your submission!
We invite visitors to our website to submit an elegant solution. Send your submission to the ponder@il.ibm.com.
If you have any problems you think we might enjoy, please send them in. All replies should be sent to: ponder@il.ibm.com
The numerical solutions are:
1.148e1174
1.609e61571
Obtaining those solutions via brute-force counting is obviously unfeasible, but there are some beautiful tricks that can be applied. First, mazes as they are defined here are nondirected trees in a graph where the vertices represent cells, and there is an edge between two adjacent cells. This is a classical method to generate mazes: construct the graph, then run Kruskal's or Prim's algorithm on it (adding weights to the graph enables one to control the shape of the generated maze). However, in this problem we don't want to generate a maze, rather to count all mazes, hence count all spanning trees of the graph.
A beautiful theorem of basic graph theory is Kirchhoff's matrix tree theorem, which reduces the enumeration of spanning trees in a general (directed/non-directed) graph to the computation of the determinant of the graph's Laplacian matrix. This is further simplified if one knows the eigenvalues of the matrix; there is at least one zero eigenvalue, and if the rest of the eigenvalues for the matrix are then the number of spanning trees is .
Directly applying the matrix tree theorem in this specific case is tricky, as the numbers were chosen so the resulting matrix is quite large. However, for the specific graph in question we can simply matters considerebly, since it can be seen as a product of two simple lines graphs. Let us denote by the graph with vertices and edges . Then the graph for the grid is where denotes the "box product" of graphs, where the vertices of are and the edges are (conceptually, the box product of graphs corresponds to the notion of trversing both graphs at the same time, taking a step in only one of the graphs each time).
For box products , if and are the eigenvalues of both graph laplacians, then the eigenvalues of the laplacian of are . Hence, the problem is reduced for finding the eigenvalues of the line graph , and it can be shown using Chebyshev polynomials that these eigenvalues are of the form for . This leads us to the formula solving the puzzle for general :
This can be slighty simplified by noting that for we have (since this is the product of eigenvalues for , which has only one spanning tree) and similarily for , so the formula simplifies to
See "The Discrete Laplacian of a Rectangular Grid " by T. Edwards for further details.
Computing the product in practice can cause numeric problems; the usual approach in such situations is computing the logarithm of the expression (trasnforming the product into a sum) and exponentiating the result.