
by George Taniwaki
In August, I became addicted to Sudoku. The puzzle has been around for several years, but I never played it. Naturally, as a data analyst, I could not just play the game for the simple pleasure of solving it. I had to track my completion times and create a model of how my completion times vary. Now that I have analyzed the game, it has ruined my enjoyment and have mostly stopped playing.
My model uses the LINEST() function in DAX to calculate linear regression coefficients and intercept. LINEST() returns a table and I could not figure out how to define a table with Power Query in Excel, so I used Power BI. If anyone knows how to use LINEST() in Excel, please add a comment to this post or DM me.
Explaining the game
For those not familiar with the game, Sudoku consists of a 9×9 grid as shown in the image at top. The grid is subdivided into nine 3×3 subgrids. Each cell in the grid can contain one of nine symbols. For simplicity, we use the numerals 1 through 9. (Thus, Sudoku is a logic game, no arithmetic is required.) Each row, column, and subgrid must contain exactly one instance of every symbol. At the start of the puzzle, some of the cells are already filled in. Your goal is the determine the correct symbols to place in the remaining cells to complete the grid. The puzzle is composed in a way that there is a unique solution. The problem has been proven to be NP-complete.
Defining a cell step and symbol removal substep
For an entirely undefined Sudoku grid, no cell has a distinct value, meaning it can have any of the 9 possible symbols, for a total of 9 x 9 x 9 = 729 possible symbols (Fig 1).

When we define a distinct value for a cell, for instance “1” in the upper left cell, we will call that a cell step. We can remove the other 8 symbols (2 through 9) from that cell. We also remove the “1” symbol from all the other cells in the row, column, and subgrid. This removes 8 + 8 + 4 = 20 “1” symbols from the grid for a total of 28 (Fig 2). We will call these symbol removal substeps.

When the puzzle is complete, all 81 cells will contain exactly 1 symbol, meaning there are 81 cell steps. There will also be only 81 symbols remaining, meaning there are a total of 648 symbol removal substeps needed to complete the puzzle (Fig 3).

As more cells have a distinct value, there are fewer symbol removal substeps at each cell step. There is no way to accurately calculate the number of remaining symbol removal substeps based on the number of remaining cell steps. Based on Figure 3 above, I calculated the number of symbol removal substeps for each cell step assuming that the symbol “1” was added to each cell starting in the subgrid in the upper left and proceeding left to right, top to bottom. The process is repeated with the symbols “2” through “9”. Table 1 shows the first 3 and last 3 rows of the results. The full table is in the Excel workbook SudokuScore.xlsx posted below and used in the model described later.
| Steps Remaining | Symbol, Subgrid | Own cell substeps | Row substeps | Column substeps | Subgrid substeps | Total substeps | Substeps Remaining |
| 81 | – | – | – | – | – | – | 648 |
| 80 | “1”, 1 | 8 | 8 | 8 | 4 | 28 | 620 |
| 79 | “1”, 2 | 8 | 5 | 7 | 2 | 22 | 598 |
| … | … | … | … | … | … | … | … |
| 2 | “9”, 7 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | “9”, 8 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | “9”, 9 | 0 | 0 | 0 | 0 | 0 | 0 |
Measuring completion time
The dependent variable for the estimation model will be completion time. During my month playing Sudoku, I used the New York Times and the Washington Post daily puzzles and played them on my mobile phone. Both newspaper apps provide a timer that displays the elapsed time. However, the timers do not start at the same point. The New York Times timer starts as soon as you open the puzzle. The Washington Post timer does not start until you remove your first symbol. For easy puzzles, it only takes a second or two before you make your first removal, so this difference is small. However, some hard puzzles open with a bottleneck (defined later) and it may take a few minutes before finding the first removal. Unfortunately, I did not discover the difference between the 2 timers until after I had started collecting data. I had to throw out my New York Times data and start over. All times presented here show elapsed time after removing the first symbol.
Measuring difficulty
Puzzles can be categorized by a level of difficulty. Puzzles are easy to solve when at at the start there is least one cell has only 1 symbol in it and removing the row, column, and subgrid symbols reveals another cell with only 1 symbol in it, allowing you to continue to the next symbol removal substep.
For example, look at the cell in the 3rd row, 9th column in the figure at the top of this blog post. It contains a single symbol, “1”. When you remove the “1”s from the row, the cell in row 3, column 7 now has only a single symbol “6” in it and you can quickly continue with symbol removal substeps.
Steps where the finding the next symbol removal substep requires careful search can be considered bottlenecks. The fewer bottlenecks, the easier the puzzle. None of the Sudoku puzzles in the New York Times or Washington Post have a step where no cells contained only a single symbol and required guessing.
Both the New York Times and the Washington Post have 3 categories of difficulty, labeled 1Easy, 2Medium, and 3Hard. While solving the puzzles, I discovered that the New York Times hard puzzles were harder than the Washington Post’s hard puzzles. I also found very little difference in solving time between the Washington Post’s hard puzzles and medium puzzles. Finally, I found the New York Times easy puzzles were very easy, meaning the New York Times Sudoku puzzles had a bigger difficulty range than the Washington Post’s.
Recording data and defining the model
During the past month, I played Sudoku puzzles and recorded my completion times in hh:mm:ss format (using the Washington Post definition of time). For each puzzle I noted the following parameters, puzzle date (which I then convert to days since I started playing), newspaper source (New York Times or Washington Post), difficulty (easy, medium, hard), player (just me), and number of cells filled at start of puzzle (which I then convert to remaining cell steps). Because it would be tedious, I did not record the number of remaining symbol removal substeps. In the model I use an estimated number of remaining symbol removal substeps using a lookup from the table described above. I did not validate the accuracy of the estimate. The raw data is recorded in the Excel workbook posted earlier.
As mentioned at the top of this blog, my multiple linear regression model transforms the Excel tables using Power Query M code in Power BI and uses the LINEST() function in DAX. My Power Query M code that transforms the raw data to variables used in LINEST() function is shown in the attached txt file and Power BI pbix file. The parameters for the LINEST() function are shown below.
Linest_Sudoku_tbl = LINEST('Sudoku_tbl'[Seconds],
'Sudoku_tbl'[Days], 'Sudoku_tbl'[Steps Remaining], 'Sudoku_tbl'[Substeps Remaining], 'Sudoku_tbl'[S_WaPo], 'Sudoku_tbl'[P_gtaniwaki], 'Sudoku_tbl'[D_1Easy], 'Sudoku_tbl'[D_2Medium], 'Sudoku_tbl'[SD_NYT_1E], 'Sudoku_tbl'[SD_NYT_2M], 'Sudoku_tbl'[SD_NYT_3H], 'Sudoku_tbl'[SD_WaPo_1E], 'Sudoku_tbl'[SD_WaPo_2M])
Results
The first step in modeling is to inspect the data for outliers and biased distribution. I used Power BI to create visuals that showed univariate and bivariate distribution of the independent and dependent variables. My report page (Fig 4) contains filters for Difficulty and Source. New York Times data in shades of maroon and Washington Post data in shades of blue. More difficult puzzle data are in darker shades. Note the 2 scatterplots at the bottom right of the report page use Power BI’s relatively new small multiples feature. Setting the filters or clicking in the charts allows drilling down for more detailed investigation.
Overall the data appears to be well behaved. As I noted above, on average, the New York Times hard puzzles were harder than the Washington Post and the easy puzzles were easier. There was little difference between the Washington Post hard and medium puzzles. My puzzle completion times show a slight decrease over time. I was getting better at it.

Selected statistics from the output of the LINEST() function are shown in Figure 5. The coefficient of determination is 0.72, which is quite high. The residual error is likely due to variations in the number of bottlenecks in a puzzle, a misestimation in the number of remaining symbol removal substeps, and puzzle solving fatigue on my part.
Note that the coefficient for [P_gtaniwaki] is zero as expected since all data was collected with me as the only player. I’m not sure why the slopes for [D_1Easy], [SD_NYT_1E], and [SD_NYT_2M] are zero. It may be because my data contains a high degree of multicolinearity and these 3 variables were not significant.

Finally, we can compare the forecast based on the LINEST() against the actual data (Fig 6) to see how close the fit with smoothing is.

Leave a Reply