房间方格是拉丁方格的一种变体。房间方格是以Thomas Room的名字命名的,虽然它也适用于建筑物的隔间,我们将在下面讨论。
在大小为n的拉丁方格中,你必须将n个符号中的一个分配给每个单元格,以便每个符号在每一行和每一列中正好出现一次。房间方格是一种有对的拉丁方格。
房间正方形的每个单元格要么是空的,要么包含一个无序的符号对。每个符号在每一行和每一列中都精确地出现一次,每一对可能的符号都出现在某个单元格中。
下面的图形显示了一个有八个符号的7×7房间方格,每个符号用不同的颜色表示。

如果你看不清某些颜色,可以看一下下面的代码,这就是图片的制作过程。
一个n×n的房间方块对应于一个有n+1名球员的循环赛时间表。每一行代表一个地点(或房间),每一列代表一个回合。每个选手在每轮比赛中打一场比赛,每对选手正好在一个地点比赛。
Python代码
这是我为创建上述图像而写的代码
import matplotlib.pyplot as plt
colors = ["red", "orange", "yellow", "green", "blue", "black", "gray", "purple"]
up, dn = True, False
def draw_triangle(row, col, value, pos):
if pos == up:
x = [col, col, col+1]
y = [row, row+1, row+1]
else:
x = [col, col+1, col+1]
y = [row, row, row+1]
plt.fill(x, y, colors[value])
sq = [
(1, 3, 0, 4),
(1, 5, 3, 5),
(1, 6, 1, 2),
(1, 7, 7, 6),
(2, 2, 6, 3),
(2, 4, 2, 4),
(2, 5, 0, 1),
(2, 6, 7, 5),
(3, 1, 5, 2),
(3, 3, 1, 3),
(3, 4, 6, 0),
(3, 5, 7, 4),
(4, 2, 0, 2),
(4, 3, 5, 6),
(4, 4, 7, 3),
(4, 7, 4, 1),
(5, 1, 6, 1),
(5, 2, 4, 5),
(5, 3, 7, 2),
(5, 6, 3, 0),
(6, 1, 3, 4),
(6, 2, 7, 1),
(6, 5, 2, 6),
(6, 7, 5, 0),
(7, 1, 7, 0),
(7, 4, 1, 5),
(7, 6, 4, 6),
(7, 7, 2, 3)
]
for t in sq:
draw_triangle(t[0], t[1], t[2], up)
draw_triangle(t[0], t[1], t[3], dn)
plt.grid()
plt.gca().set_aspect("equal")
plt.show()