Finding all valid 5×5 sudoku/bingo boards where diagonals must also be unique

algorithmslatin-squaremagic squaresudoku

I'm working on a personal project to create a bingo card for a video game. The bingo card contains items the player can use during normal play, and my goal is to be able to generate a bingo board where every row, diagonal, and column has the same amount of each type of item, not the same exact items.

Put in mathematical terms, suppose I wish to construct a bingo board from n=5 categories of things, where each row, column, and diagonal sees one element from each of the n categories.

One possible valid board is as follows:

D B A C E
B C E A D
E A B D C
A D C E B
C E D B A

Each row, column, and diagonal has 1A, 1B, 1C, 1D, and 1E.

Now the part that I'm having trouble with is… that's just one valid board. I'm hoping to be able to write an algorithm that can generate any and all such valid boards. I understand that simple ways to alter this example board would be swapping around the letters, or rotating the board, but I'm curious if there are other "configurations" of the board that could work as well. I'm not confident that would be all of the possible combinations.

Am I on the right track? How do I find all possible combinations of the "1A,1B,1C,1D,1E" board? Is there a mathematical way that could elegantly be turned into an algorithm?

Best Answer

Up to rotations, reflections, and permuting the letters, there are only three possible $5 \times 5$ "Sudoku bingo cards".

To see this, let's consider just one letter: the letter we put in the top left corner. Let's say it's A. By some casework, we see that there are four ways to fill in the rest of the A's: the two grids below, and their diagonal reflections.

A....     A....
..A..     ...A.
....A     ....A
.A...     ..A..
...A.     .A...

I will call these two patterns the "dipper" and the "slingshot", respectively.

We can go on to consider the letter in the top right corner; say it's B. We can combine an A-dipper or an A-slingshot with a B-dipper and a B-slingshot in exactly one way. (Though there are two ways to draw the B-dipper and two ways to draw the B-slingshot, since we can reflect through the diagonal, we can choose only one of them if we want to avoid collisions.)

Once we place the A's and B's, it turns out there is only one way to complete the rest of the grid, if we say that the letter in the bottom right is C, the letter in the bottom left is D, and the remaining letter is E. Also, picking a "dipper" for A and a "slingshot" for B is symmetric to picking a "slingshot" for A and a "dipper" for B. So we get three results:

ACDEB     ACDEB     AEDCB
EBACD     BDACE     BDCAE
CDEBA     CBEDA     CBEDA
BACDE     EACBD     ECABD
DEBAC     DEBAC     DABEC

In the end, the first square is the one in which A, B, C, and D all form "dippers". In the second, they form two "dippers" and two "slingshots"; in the third square, all four form "slingshots".

Related Question