Tool to create or solve Latin squares, a square grid of NxN with N distinct symbols distributed without repetition in each row and column, ideal for lovers of logic and puzzles similar to sudoku.
Latin Square - dCode
Tag(s) : Number Games
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
A Latin square is a square of size $ n \times n $ filled with exactly $ n $ distinct symbols (letters, numbers, numbers) so that each symbol appears only once per row and per column.
Example: A 3x3 Latin square:
1 | 2 | 3 |
3 | 1 | 2 |
2 | 3 | 1 |
There are several methods for generating Latin squares. Here is the shortest to explain:
1- Take an empty NxN grid,
Example:
- | - | - |
- | - | - |
- | - | - |
2- Fill the first row with N symbols
Example:
A | B | C |
- | - | - |
- | - | - |
3- Fill the next row by shifting all the symbols by 1 box to the right (and return to the beginning of the row if necessary)
Example:
A | B | C |
C | A | B |
- | - | - |
4- Repeat step 3 until you reach the last row of the grid.
Example:
A | B | C |
C | A | B |
B | C | A |
And voilà! The square is thus valid but always identical, to obtain others:
5- Randomly swap 2 lines
6- Randomly swap 2 columns
7- Repeat steps 5 and 6 as many times as desired, the result is always a Latin square.
There are variants of Latin squares with additional constraints, such as diagonal Latin squares where each symbol must also be unique on both long diagonals of the grid.
The resolution algorithm consists in noting, for each unfilled cell, the list of possible symbols respecting the rules (prohibition of 2 identical symbols on the same row or the same column), if only one symbol among the N is possible then fill in the cell with this symbol.
The Latin square name comes from Leonhard Euler who studied these grids and who used Latin letters as symbols.
The best known variant is sudoku, which uses the same bases, but adds a constraint on blocks of 3x3 (and sometimes other constraints for irregular sudoku).
Ken-ken (kendoku) is also a Latin square with constraints of mathematical calculations.
The magic square is a distant mathematical variant which takes up the fact that the sum of the rows and the columns is always identical, but it is not limited to N distinct symbols.
The number of possible Latin squares increases rapidly with the size of $ N $. For $ N = 3 $ there are 12 different Latin squares, for $ N = 4 $ there are 576, then 161280 for 5, 812851200 for 6 etc. for larger sizes this number becomes exponential, see here
No direct formula to find these numbers is known to date.
The first written traces of work on these grids date from 1700, but the principle itself was known long before, perhaps even from antiquity.
dCode retains ownership of the "Latin Square" source code. Any algorithm for the "Latin Square" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Latin Square" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Latin Square" or any other element are not public (except explicit open source licence like Creative Commons). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Latin Square" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source.
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Latin Square on dCode.fr [online website], retrieved on 2025-04-16,