4

How many 7 by 7 Latin squares are there, and how can one generate examples of them? I am working on classes for a game, and typing in numbers manually from 1-7 in rows and columns from scratch is exceedingly difficult. From what I can tell there are no generators for this type of thing online.

Yes I can type in 1-2-3-4-5-6-7, then the next row 3-4-5-6-7-1-2, but that does not work so well with stats of classes in a game.

Diagonals do NOT have to be 1-7. Rows and columns must have a unique number per square.

xnor
  • 26,756
  • 4
  • 85
  • 144
Dan
  • 41
  • 3

2 Answers2

8

There are 61479419904000 seven by seven Latin squares. This is from OEIS, and hard to calculate in general.

If you just want to generate Latin squares quickly, you have a few options. One is quick and lazy: take a few template squares, and then generate more by permuting the rows, columns, and/or numbers. If you're comfortable with programming, you can write a quick backtracking solver. Or you could use this site. (Easy to Google once you know they're called, eh?)

Lopsy
  • 7,964
  • 30
  • 54
0

Note that for any nxn, with n being odd, there's a trivial solution where even the diagonals work:

1 6 4 2 7 5
2 7 5 3 1 6
3 1 6 4 2 7
4 2 7 5 3 1
5 3 1 6 4 2
6 4 2 7 5 3
7 5 3 1 6 4

Just start with 1-n in the first column, and in each next column shift down 2 positions ('as the knight jumps', if you will).

That's however only a partial answer, on how you can generate an example. Given your intended purpose I think you're more looking into a 'randomlooking' example?

EDIT: Only after typing this up, I found it's covered in this question aswell, but in more detail.

Tim Couwelier
  • 4,349
  • 21
  • 37