我的孩子们有这个有趣的游戏叫Spot It!游戏限制(我能说的最好)是:
游戏的原则是:翻转2张牌,无论谁先挑选匹配的图片都能获得一分。
以下是澄清的图片:
(例如:你可以从上面的2张牌看到匹配的图片是绿色恐龙。在右下角和中右图之间,它是一个小丑的头。)
我正在尝试理解以下内容:
满足这些标准所需的最小不同照片数量是多少?您如何确定?
使用伪代码(或Ruby),如何从N个图片阵列中生成55张游戏卡(其中N是问题1中的最小数字)?
更新
图片确实每张纸牌发生两次以上(与某些人猜测的相反)。查看3张卡的图片,每张卡都带有闪电:
答案 0 :(得分:144)
有限投影几何
axioms的projective (plane) geometry与欧几里德几何略有不同:
现在,将"finite"添加到汤中,您就有了问题:
我们的几何体只有2个点吗?有3分? 4?有7?
关于这个问题仍有待解决的问题,但我们知道这一点:
Q
点的几何图形,则Q = n^2 + n + 1
和n
称为几何图形的order
。n+1
分。n+1
行。总行数也是Q
。
最后,如果n
是素数,那么确实存在一个订单n
的几何。
有人可能会问,这与谜题有什么关系。
将card
代替point
和picture
而不是line
,公理成为:
现在,我们来n=7
,order-7
有限几何与Q = 7^2 + 7 + 1
。这会使Q=57
行(图片)和Q=57
点(卡片)。我猜拼图制造商认为55是圆形数字而不是57,剩下2张卡片。
我们也得到n+1 = 8
,所以从每个点(卡片)开始,8行通过(出现8张图片),每行(图片)有8个点(出现在8张卡片中)。
以下是从Fano Plane复制的最着名的有限投影(阶2)平面(几何)的表示,其中包含7个点,称为Noelle Evans - Finite Geometry Problem Page
我正在考虑创建一个图像来解释如何将上面的2阶平面与7张卡片和7张图片组成一个类似的拼图,但是来自math.exchange双胞胎问题的链接正是这样一个图表:<强> Dobble-et-la-geometrie-finie 强>
答案 1 :(得分:18)
因此, k = 55 卡中包含 m = 8 图片,每张图片来自 n 图片总计。 我们可以重申“我们需要多少张图片 n 这样的问题,这样我们就可以构建一组 k 卡片,在任何一对卡片之间只有一张共享图片?”等同地问:
给定一个 n 维度向量空间和所有向量的集合,其中包含等于一个的所有其他零 m 元素,有多大n ,以便我们可以找到一组 k 向量,其成对点积等于 1 ?
确实( n 选择 m )可能的向量来构建对。所以我们至少需要足够大的 n 以便( n 选择 m )&gt; = k 。这只是一个下限,因此为了实现成对兼容性约束,我们可能需要更高的 n 。
仅仅为了实验,我写了一个小的Haskell程序来计算有效的卡片组:
编辑:我在看到Neil和Gajet的解决方案后才意识到,我使用的算法并不总能找到最佳解决方案,因此下面的所有内容都不一定有效。我会尽快更新我的代码。
module Main where
cardCandidates n m = cardCandidates' [] (n-m) m
cardCandidates' buildup 0 0 = [buildup]
cardCandidates' buildup zc oc
| zc>0 && oc>0 = zerorec ++ onerec
| zc>0 = zerorec
| otherwise = onerec
where zerorec = cardCandidates' (0:buildup) (zc-1) oc
onerec = cardCandidates' (1:buildup) zc (oc-1)
dot x y = sum $ zipWith (*) x y
compatible x y = dot x y == 1
compatibleCards = compatibleCards' []
compatibleCards' valid [] = valid
compatibleCards' valid (c:cs)
| all (compatible c) valid = compatibleCards' (c:valid) cs
| otherwise = compatibleCards' valid cs
legalCardSet n m = compatibleCards $ cardCandidates n m
main = mapM_ print [(n, length $ legalCardSet n m) | n<-[m..]]
where m = 8
m 的最大兼容卡数量=每张卡8张图片,可供 n 选择不同数量的图片 n 看起来像这样:
由于组合爆炸,这种蛮力方法并没有走得太远。但我认为它可能仍然很有趣。
有趣的是,似乎对于给定的 m , k 随着 n 的增加而增加到某个 n 之后它保持不变。
这意味着,对于每张卡的每个图片数量,可以选择一定数量的图片,这样可以获得最大数量的合法卡片。添加更多图片以从过去的最佳数字中进行选择不会进一步增加合法卡的数量。
前几个最佳 k 是:
答案 2 :(得分:16)
对于那些无法用57个点描绘投影平面几何体的人来说,有一个非常好的,直观的方法来构建57张牌和57个符号的游戏(基于Yuval Filmus的答案{{3 }}):
在这个例子中,我采用斜率为零(红色)的一条线和一条斜率为1的线(绿色)。它们恰好在一个共同点(猫头鹰)相交。
此方法可确保任意两张卡只有一个共同的符号,因为
通过这种方式,我们可以构建7x7卡(7个偏移和7个斜率)。
我们还可以通过网格从垂直线构建另外七张牌(即每列)。对于那些,使用无限斜率图标。
因为每张卡由网格中的七个符号和一个“斜率”符号组成,我们可以创建一个附加卡,它只包含所有8个斜率符号。
这给我们留下了7x8 + 1 = 57张可能的牌,7 x 7 + 8 = 57张所需的牌。
(当然,这仅适用于素数大小的网格(例如n = 7)。否则,如果斜率是网格大小的除数,则不同斜率的线可以具有零个或多个交点。)
答案 3 :(得分:9)
其他人已经描述了设计的一般框架(有限投影平面),并展示了如何生成素数阶的有限投影平面。我想填补一些空白。
可以为许多不同的阶数生成有限投影平面,但在素数阶p
的情况下,它们最直接。然后,模p
的整数形成一个有限域,可用于描述平面中点和线的坐标。点数有3种不同的坐标:(1,x,y)
,(0,1,x)
和(0,0,1)
,其中x
和y
可以采用0
的值到p-1
。 3种不同的点解释了系统中点数的公式p^2+p+1
。我们还可以描述具有相同3种不同坐标的线:[1,x,y]
,[0,1,x]
和[0,0,1]
。
我们通过坐标的点积是否等于0 mod p
来计算点和线是否发生。例如,点(1,2,5)
和行[0,1,1]
在p=7
后1*0+2*1+5*1 = 7 == 0 mod 7
发生,但点(1,3,3)
和行[1,2,6]
是自1*1+3*2+3*6 = 25 != 0 mod 7
以来没有发生事故。
翻译成卡片和图片的语言,这意味着坐标为(1,2,5)
的卡片中包含坐标为[0,1,1]
的图片,但坐标为(1,3,3)
的卡片中不包含坐标[1,2,6]
。我们可以使用此程序开发完整的卡片列表及其中包含的图片。
顺便说一句,我认为将图片看作点和卡就像线条一样容易,但点和线之间的投影几何图形存在二元性,所以它确实无关紧要。但是,在下文中,我将使用点卡片和卡片线。
同样的结构适用于任何有限的场。我们知道有一个有限的秩序q
,当且仅当q=p^k
是一个主要的力量。该字段称为GF(p^k)
,代表“Galois字段”。在主要权力案例中,这些字段并不像在素数情况下那样容易构建。
幸运的是,辛勤工作已经在自由软件中完成并实施,即Sage。例如,要获得阶数为4的投影平面设计,只需输入
即可print designs.ProjectiveGeometryDesign(2,1,GF(4,'z'))
你将获得看起来像
的输出ProjectiveGeometryDesign<points=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20], blocks=[[0, 1, 2, 3, 20], [0,
4, 8, 12, 16], [0, 5, 10, 15, 19], [0, 6, 11, 13, 17], [0, 7, 9, 14,
18], [1, 4, 11, 14, 19], [1, 5, 9, 13, 16], [1, 6, 8, 15, 18], [1, 7,
10, 12, 17], [2, 4, 9, 15, 17], [2, 5, 11, 12, 18], [2, 6, 10, 14, 16],
[2, 7, 8, 13, 19], [3, 4, 10, 13, 18], [3, 5, 8, 14, 17], [3, 6, 9, 12,
19], [3, 7, 11, 15, 16], [4, 5, 6, 7, 20], [8, 9, 10, 11, 20], [12, 13,
14, 15, 20], [16, 17, 18, 19, 20]]>
我将上述内容解释如下:有21张标记为0到20的图片。每个图块(投影几何图形中的线条)告诉我哪些图片出现在卡片上。例如,第一张卡片将包含图片0,1,2,3和20;第二张卡片上有0,4,8,12和16张图片;等等。
订单7的系统可以由
生成print designs.ProjectiveGeometryDesign(2,1,GF(7))
生成输出
ProjectiveGeometryDesign<points=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56], blocks=[[0, 1, 2, 3, 4, 5, 6,
56], [0, 7, 14, 21, 28, 35, 42, 49], [0, 8, 16, 24, 32, 40, 48, 50], [0,
9, 18, 27, 29, 38, 47, 51], [0, 10, 20, 23, 33, 36, 46, 52], [0, 11, 15,
26, 30, 41, 45, 53], [0, 12, 17, 22, 34, 39, 44, 54], [0, 13, 19, 25,
31, 37, 43, 55], [1, 7, 20, 26, 32, 38, 44, 55], [1, 8, 15, 22, 29, 36,
43, 49], [1, 9, 17, 25, 33, 41, 42, 50], [1, 10, 19, 21, 30, 39, 48,
51], [1, 11, 14, 24, 34, 37, 47, 52], [1, 12, 16, 27, 31, 35, 46, 53],
[1, 13, 18, 23, 28, 40, 45, 54], [2, 7, 19, 24, 29, 41, 46, 54], [2, 8,
14, 27, 33, 39, 45, 55], [2, 9, 16, 23, 30, 37, 44, 49], [2, 10, 18, 26,
34, 35, 43, 50], [2, 11, 20, 22, 31, 40, 42, 51], [2, 12, 15, 25, 28,
38, 48, 52], [2, 13, 17, 21, 32, 36, 47, 53], [3, 7, 18, 22, 33, 37, 48,
53], [3, 8, 20, 25, 30, 35, 47, 54], [3, 9, 15, 21, 34, 40, 46, 55], [3,
10, 17, 24, 31, 38, 45, 49], [3, 11, 19, 27, 28, 36, 44, 50], [3, 12,
14, 23, 32, 41, 43, 51], [3, 13, 16, 26, 29, 39, 42, 52], [4, 7, 17, 27,
30, 40, 43, 52], [4, 8, 19, 23, 34, 38, 42, 53], [4, 9, 14, 26, 31, 36,
48, 54], [4, 10, 16, 22, 28, 41, 47, 55], [4, 11, 18, 25, 32, 39, 46,
49], [4, 12, 20, 21, 29, 37, 45, 50], [4, 13, 15, 24, 33, 35, 44, 51],
[5, 7, 16, 25, 34, 36, 45, 51], [5, 8, 18, 21, 31, 41, 44, 52], [5, 9,
20, 24, 28, 39, 43, 53], [5, 10, 15, 27, 32, 37, 42, 54], [5, 11, 17,
23, 29, 35, 48, 55], [5, 12, 19, 26, 33, 40, 47, 49], [5, 13, 14, 22,
30, 38, 46, 50], [6, 7, 15, 23, 31, 39, 47, 50], [6, 8, 17, 26, 28, 37,
46, 51], [6, 9, 19, 22, 32, 35, 45, 52], [6, 10, 14, 25, 29, 40, 44,
53], [6, 11, 16, 21, 33, 38, 43, 54], [6, 12, 18, 24, 30, 36, 42, 55],
[6, 13, 20, 27, 34, 41, 48, 49], [7, 8, 9, 10, 11, 12, 13, 56], [14, 15,
16, 17, 18, 19, 20, 56], [21, 22, 23, 24, 25, 26, 27, 56], [28, 29, 30,
31, 32, 33, 34, 56], [35, 36, 37, 38, 39, 40, 41, 56], [42, 43, 44, 45,
46, 47, 48, 56], [49, 50, 51, 52, 53, 54, 55, 56]]>
答案 4 :(得分:8)
我刚刚找到了用57或58张照片做的方法,但是现在我头痛得很厉害,我会在睡了8到10个小时后发布红宝石代码!只是暗示我的解决方案每7张卡共享相同的标记,并且可以使用我的解决方案构建总共56张卡。
这里是生成ypercube正在讨论的所有57张卡片的代码。它只使用了57张图片,对不起,我已经编写了实际的C ++代码,但知道vector <something>
是一个包含something
类型值的数组,很容易理解这段代码的作用。此代码使用P^2+P+1
张照片生成P^2+P+1
张卡片,每张照片包含P+1
张照片,并且每张素数P值共享一张共同的照片。这意味着我们可以使用7张照片,每张照片有3张照片(p = 2),13张照片使用13张照片(p = 3张),31张照片使用31张照片(p = 5张),57张牌照57张照片(对于p = 7)等等......
#include <iostream>
#include <vector>
using namespace std;
vector <vector<int> > cards;
void createcards(int p)
{
cards.resize(0);
for (int i=0;i<p;i++)
{
cards.resize(cards.size()+1);
for(int j=0;j<p;j++)
{
cards.back().push_back(i*p+j);
}
cards.back().push_back(p*p+1);
}
for (int i=0;i<p;i++)
{
for(int j=0;j<p;j++)
{
cards.resize(cards.size()+1);
for(int k=0;k<p;k++)
{
cards.back().push_back(k*p+(j+i*k)%p);
}
cards.back().push_back(p*p+2+i);
}
}
cards.resize(cards.size()+1);
for (int i=0;i<p+1;i++)
cards.back().push_back(p*p+1+i);
}
void checkCards()
{
cout << "---------------------\n";
for(unsigned i=0;i<cards.size();i++)
{
for(unsigned j=0;j<cards[i].size();j++)
{
printf("%3d",cards[i][j]);
}
cout << "\n";
}
cout << "---------------------\n";
for(unsigned i=0;i<cards.size();i++)
{
for(unsigned j=i+1;j<cards.size();j++)
{
int sim = 0;
for(unsigned k=0;k<cards[i].size();k++)
for(unsigned l=0;l<cards[j].size();l++)
if (cards[i][k] == cards[j][l])
sim ++;
if (sim != 1)
cout << "there is a problem between cards : " << i << " " << j << "\n";
}
}
}
int main()
{
int p;
for(cin >> p; p!=0;cin>> p)
{
createcards(p);
checkCards();
}
}
再次抱歉延迟代码。
答案 5 :(得分:6)
这是Gajet在Python中的解决方案,因为我发现Python更具可读性。我修改了它,以便它也适用于非素数。我使用Thies insight来生成一些更容易理解的显示代码。
from __future__ import print_function
from itertools import *
def create_cards(p):
for min_factor in range(2, 1 + int(p ** 0.5)):
if p % min_factor == 0:
break
else:
min_factor = p
cards = []
for i in range(p):
cards.append(set([i * p + j for j in range(p)] + [p * p]))
for i in range(min_factor):
for j in range(p):
cards.append(set([k * p + (j + i * k) % p
for k in range(p)] + [p * p + 1 + i]))
cards.append(set([p * p + i for i in range(min_factor + 1)]))
return cards, p * p + p + 1
def display_using_stars(cards, num_pictures):
for pictures_for_card in cards:
print("".join('*' if picture in pictures_for_card else ' '
for picture in range(num_pictures)))
def check_cards(cards):
for card, other_card in combinations(cards, 2):
if len(card & other_card) != 1:
print("Cards", sorted(card), "and", sorted(other_card),
"have intersection", sorted(card & other_card))
cards, num_pictures = create_cards(7)
display_using_stars(cards, num_pictures)
check_cards(cards)
输出:
*** *
*** *
****
* * * *
* * * *
* * * *
* * * *
* ** *
** * *
* * * *
* * * *
* * * *
****
答案 6 :(得分:4)
我非常喜欢这个帖子。我使用此代码的一部分构建此github python项目,以将自定义卡片绘制为png(因此可以在互联网上订购自定义卡片游戏)。
答案 7 :(得分:3)
使用z3
定理证明器
让P
为每张卡片的符号数。根据{{3}}和ypercubeᵀᴹ
的回答,分别有N = P**2 - P + 1
张卡片和符号。一副牌可以用其入射矩阵表示,每个卡有一行,每个可能符号有一列。如果卡(i,j)
上有符号1
,则其i
元素为j
。我们只需要考虑这些约束来填充这个矩阵:
P
P
这意味着N**2
变量和N**2 + 2*N + (N choose 2)
约束。对于小输入,z3
似乎可以在不太长的时间内进行管理。
编辑:不幸的是,对于这种方法,P = 8似乎太大了。我在14小时的计算时间后杀了这个过程。
from z3 import *
from itertools import combinations
def is_prime_exponent(K):
return K > 1 and K not in 6 # next non-prime exponent is 10,
# but that is too big anyway
def transposed(rows):
return zip(*rows)
def spotit_z3(symbols_per_card):
K = symbols_per_card - 1
N = symbols_per_card ** 2 - symbols_per_card + 1
if not is_prime_exponent(K):
raise TypeError("Symbols per card must be a prime exponent plus one.")
constraints = []
# the rows of the incidence matrix
s = N.bit_length()
rows = [[BitVec("r%dc%d" % (r, c), s) for c in range(N)] for r in range(N)]
# every element must be either 1 or 0
constraints += [Or([elem == 1, elem == 0]) for row in rows for elem in row]
# sum of rows and cols must be exactly symbols_per_card
constraints += [Sum(row) == symbols_per_card for row in rows]
constraints += [Sum(col) == symbols_per_card for col in transposed(rows)]
# Any two rows must have exactly one symbol in common, in other words they
# differ in (symbols_per_card - 1) symbols, so their element-wise XOR will
# have 2 * (symbols_per_card - 1) ones.
D = 2 * (symbols_per_card - 1)
for row_a, row_b in combinations(rows, 2):
constraints += [Sum([a ^ b for a, b in zip(row_a, row_b)]) == D]
solver = Solver()
solver.add(constraints)
if solver.check() == unsat:
raise RuntimeError("Could not solve it :(")
# create the incidence matrix
model = solver.model()
return [[model[elem].as_long() for elem in row] for row in rows]
if __name__ == "__main__":
import sys
symbols_per_card = int(sys.argv[1])
incidence_matrix = spotit_z3(symbols_per_card)
for row in incidence_matrix:
print(row)
<强>结果
$python spotit_z3.py 3
[0, 0, 1, 1, 0, 1, 0]
[0, 0, 0, 0, 1, 1, 1]
[0, 1, 0, 1, 0, 0, 1]
[1, 1, 0, 0, 0, 1, 0]
[0, 1, 1, 0, 1, 0, 0]
[1, 0, 0, 1, 1, 0, 0]
[1, 0, 1, 0, 0, 0, 1]
python spotit_z3.py 3 1.12s user 0.06s system 96% cpu 1.225 total
$ time python3 spotit_z3.py 4
[0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0]
[0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0]
[0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1]
[0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0]
[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1]
[0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1]
[0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0]
[0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0]
[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]
[1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0]
[1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0]
[1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]
python spotit_z3.py 4 664.62s user 0.15s system 99% cpu 11:04.88 total
$ time python3 spotit_z3.py 5
[1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0]
[0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
[0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1]
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]
[0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1]
[1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0]
[0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0]
[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1]
[1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0]
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1]
[1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0]
python spotit_z3.py 5 1162.72s user 20.34s system 99% cpu 19:43.39 total
$ time python3 spotit_z3.py 8
<I killed it after 14 hours of run time.>
答案 8 :(得分:2)
我写了article关于如何使用Perl中的代码生成这种类型的套牌。代码没有经过优化,但它至少能够生成“合理”订单的套牌......还有更多。
这是一个8阶的例子,它必须考虑稍微复杂的基础数学,因为8虽然是生成这类甲板的有效顺序,但不是素数。如果您只想生成稍微困难的Spot-It,请参阅上文或文章以获取更详细的说明: - )
$ time pg2 8
elements in field: 8
0. (1, 9, 17, 25, 33, 41, 49, 57, 65)
1. (0, 9, 10, 11, 12, 13, 14, 15, 16)
2. (2, 9, 18, 27, 36, 45, 54, 63, 72)
3. (6, 9, 22, 26, 37, 43, 56, 60, 71)
4. (7, 9, 23, 32, 34, 46, 52, 59, 69)
5. (8, 9, 24, 30, 35, 42, 55, 61, 68)
6. (3, 9, 19, 29, 39, 44, 50, 64, 70)
7. (4, 9, 20, 31, 38, 48, 53, 58, 67)
8. (5, 9, 21, 28, 40, 47, 51, 62, 66)
9. (0, 1, 2, 3, 4, 5, 6, 7, 8)
10. (1, 10, 18, 26, 34, 42, 50, 58, 66)
11. (1, 14, 22, 30, 38, 46, 54, 62, 70)
12. (1, 15, 23, 31, 39, 47, 55, 63, 71)
13. (1, 16, 24, 32, 40, 48, 56, 64, 72)
14. (1, 11, 19, 27, 35, 43, 51, 59, 67)
15. (1, 12, 20, 28, 36, 44, 52, 60, 68)
16. (1, 13, 21, 29, 37, 45, 53, 61, 69)
17. (0, 17, 18, 19, 20, 21, 22, 23, 24)
18. (2, 10, 17, 28, 35, 46, 53, 64, 71)
19. (6, 14, 17, 29, 34, 48, 51, 63, 68)
20. (7, 15, 17, 26, 40, 44, 54, 61, 67)
21. (8, 16, 17, 27, 38, 47, 50, 60, 69)
22. (3, 11, 17, 31, 37, 42, 52, 62, 72)
23. (4, 12, 17, 30, 39, 45, 56, 59, 66)
24. (5, 13, 17, 32, 36, 43, 55, 58, 70)
25. (0, 49, 50, 51, 52, 53, 54, 55, 56)
26. (3, 10, 20, 30, 40, 43, 49, 63, 69)
27. (2, 14, 21, 32, 39, 42, 49, 60, 67)
28. (8, 15, 18, 28, 37, 48, 49, 59, 70)
29. (6, 16, 19, 31, 36, 46, 49, 61, 66)
30. (5, 11, 23, 26, 38, 45, 49, 64, 68)
31. (7, 12, 22, 29, 35, 47, 49, 58, 72)
32. (4, 13, 24, 27, 34, 44, 49, 62, 71)
33. (0, 57, 58, 59, 60, 61, 62, 63, 64)
34. (4, 10, 19, 32, 37, 47, 54, 57, 68)
35. (5, 14, 18, 31, 35, 44, 56, 57, 69)
36. (2, 15, 24, 29, 38, 43, 52, 57, 66)
37. (3, 16, 22, 28, 34, 45, 55, 57, 67)
38. (7, 11, 21, 30, 36, 48, 50, 57, 71)
39. (6, 12, 23, 27, 40, 42, 53, 57, 70)
40. (8, 13, 20, 26, 39, 46, 51, 57, 72)
41. (0, 65, 66, 67, 68, 69, 70, 71, 72)
42. (5, 10, 22, 27, 39, 48, 52, 61, 65)
43. (3, 14, 24, 26, 36, 47, 53, 59, 65)
44. (6, 15, 20, 32, 35, 45, 50, 62, 65)
45. (2, 16, 23, 30, 37, 44, 51, 58, 65)
46. (4, 11, 18, 29, 40, 46, 55, 60, 65)
47. (8, 12, 21, 31, 34, 43, 54, 64, 65)
48. (7, 13, 19, 28, 38, 42, 56, 63, 65)
49. (0, 25, 26, 27, 28, 29, 30, 31, 32)
50. (6, 10, 21, 25, 38, 44, 55, 59, 72)
51. (8, 14, 19, 25, 40, 45, 52, 58, 71)
52. (4, 15, 22, 25, 36, 42, 51, 64, 69)
53. (7, 16, 18, 25, 39, 43, 53, 62, 68)
54. (2, 11, 20, 25, 34, 47, 56, 61, 70)
55. (5, 12, 24, 25, 37, 46, 50, 63, 67)
56. (3, 13, 23, 25, 35, 48, 54, 60, 66)
57. (0, 33, 34, 35, 36, 37, 38, 39, 40)
58. (7, 10, 24, 31, 33, 45, 51, 60, 70)
59. (4, 14, 23, 28, 33, 43, 50, 61, 72)
60. (3, 15, 21, 27, 33, 46, 56, 58, 68)
61. (5, 16, 20, 29, 33, 42, 54, 59, 71)
62. (8, 11, 22, 32, 33, 44, 53, 63, 66)
63. (2, 12, 19, 26, 33, 48, 55, 62, 69)
64. (6, 13, 18, 30, 33, 47, 52, 64, 67)
65. (0, 41, 42, 43, 44, 45, 46, 47, 48)
66. (8, 10, 23, 29, 36, 41, 56, 62, 67)
67. (7, 14, 20, 27, 37, 41, 55, 64, 66)
68. (5, 15, 19, 30, 34, 41, 53, 60, 72)
69. (4, 16, 21, 26, 35, 41, 52, 63, 70)
70. (6, 11, 24, 28, 39, 41, 54, 58, 69)
71. (3, 12, 18, 32, 38, 41, 51, 61, 71)
72. (2, 13, 22, 31, 40, 41, 50, 59, 68)
errors in check: 0
real 0m0.303s
user 0m0.200s
sys 0m0.016s
0
到72
的每个标识符都可以作为卡标识符和图片标识符读取。例如,最后一行表示:
72
包含图片2
,13
,22
,...,59
,68
,和72
出现在卡2
,13
,22
,...,59
和68
中。答案 9 :(得分:0)
我编写了以下代码来计算卡片。这个想法是创建第一张带有 n 个图像的卡片。如果每对图像索引的差异是唯一的,则可以通过使用相同的值增加每个索引以模 m = n * n - n + 1 来简单地生成其余的卡片
static public int[] Backtrack(int n)
{
int m = n * n - n + 1;
int[] Check = new int[m];
int C = 1;
int[] T = new int[n];
int _p = 2;
T[1] = 1;
if (n > 2) T[2] = 1;
else return T;
while (_p >= 2)
{
T[_p]++;
if (T[_p] == m)
{
_p--;
continue;
}
bool good = true;
C++;
for (int i = 0; i <= _p; i++)
{
for (int j = 0; j < i; j++)
{
int x = (T[i] - T[j] + m) % m;
if (Check[x] == C || Check[m - x] == C)//x cannot be equal to m-x as m is odd.
good = false;
Check[m - x] = C;
Check[x] = C;
}
}
if (good)
{
_p++;
if (_p == n)
{
_p--;
return T;
}
T[_p] = T[_p - 1];
}
}
return new int[] { };
}
static void Main(string[] args)
{
for (int N = 2; N < 11; N++)
{
var X = Backtrack(N);
if (X.Length > 0)
{
int K = N * N - N + 1;
Console.WriteLine("Cards: {0} Order {1}:", K, N - 1);
int C = 0;
for (int j = 0; j < K; j++)
{
Console.Write("Card {0:000}:", C++);
for (int i = 0; i < N; i++)
{
var t = (X[i] + j) % K;
if (j != 0 && Array.Exists(X, x => (x == t)))
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("\t{0}", t);
Console.ResetColor();
}
Console.WriteLine();
}
}
}
}
输出:
Cards: 3 Order 1:
Card 000: 0 1
Card 001: 1 2
Card 002: 2 0
Cards: 7 Order 2:
Card 000: 0 1 3
Card 001: 1 2 4
Card 002: 2 3 5
Card 003: 3 4 6
Card 004: 4 5 0
Card 005: 5 6 1
Card 006: 6 0 2
Cards: 13 Order 3:
Card 000: 0 1 3 9
Card 001: 1 2 4 10
Card 002: 2 3 5 11
Card 003: 3 4 6 12
Card 004: 4 5 7 0
Card 005: 5 6 8 1
Card 006: 6 7 9 2
Card 007: 7 8 10 3
Card 008: 8 9 11 4
Card 009: 9 10 12 5
Card 010: 10 11 0 6
Card 011: 11 12 1 7
Card 012: 12 0 2 8
Cards: 21 Order 4:
Card 000: 0 1 4 14 16
Card 001: 1 2 5 15 17
Card 002: 2 3 6 16 18
Card 003: 3 4 7 17 19
Card 004: 4 5 8 18 20
Card 005: 5 6 9 19 0
Card 006: 6 7 10 20 1
Card 007: 7 8 11 0 2
Card 008: 8 9 12 1 3
Card 009: 9 10 13 2 4
Card 010: 10 11 14 3 5
Card 011: 11 12 15 4 6
Card 012: 12 13 16 5 7
Card 013: 13 14 17 6 8
Card 014: 14 15 18 7 9
Card 015: 15 16 19 8 10
Card 016: 16 17 20 9 11
Card 017: 17 18 0 10 12
Card 018: 18 19 1 11 13
Card 019: 19 20 2 12 14
Card 020: 20 0 3 13 15
Cards: 31 Order 5:
Card 000: 0 1 3 8 12 18
Card 001: 1 2 4 9 13 19
Card 002: 2 3 5 10 14 20
Card 003: 3 4 6 11 15 21
Card 004: 4 5 7 12 16 22
Card 005: 5 6 8 13 17 23
Card 006: 6 7 9 14 18 24
Card 007: 7 8 10 15 19 25
Card 008: 8 9 11 16 20 26
Card 009: 9 10 12 17 21 27
Card 010: 10 11 13 18 22 28
Card 011: 11 12 14 19 23 29
Card 012: 12 13 15 20 24 30
Card 013: 13 14 16 21 25 0
Card 014: 14 15 17 22 26 1
Card 015: 15 16 18 23 27 2
Card 016: 16 17 19 24 28 3
Card 017: 17 18 20 25 29 4
Card 018: 18 19 21 26 30 5
Card 019: 19 20 22 27 0 6
Card 020: 20 21 23 28 1 7
Card 021: 21 22 24 29 2 8
Card 022: 22 23 25 30 3 9
Card 023: 23 24 26 0 4 10
Card 024: 24 25 27 1 5 11
Card 025: 25 26 28 2 6 12
Card 026: 26 27 29 3 7 13
Card 027: 27 28 30 4 8 14
Card 028: 28 29 0 5 9 15
Card 029: 29 30 1 6 10 16
Card 030: 30 0 2 7 11 17
Cards: 57 Order 7:
Card 000: 0 1 3 13 32 36 43 52
Card 001: 1 2 4 14 33 37 44 53
Card 002: 2 3 5 15 34 38 45 54
Card 003: 3 4 6 16 35 39 46 55
Card 004: 4 5 7 17 36 40 47 56
Card 005: 5 6 8 18 37 41 48 0
Card 006: 6 7 9 19 38 42 49 1
Card 007: 7 8 10 20 39 43 50 2
Card 008: 8 9 11 21 40 44 51 3
Card 009: 9 10 12 22 41 45 52 4
Card 010: 10 11 13 23 42 46 53 5
Card 011: 11 12 14 24 43 47 54 6
Card 012: 12 13 15 25 44 48 55 7
Card 013: 13 14 16 26 45 49 56 8
Card 014: 14 15 17 27 46 50 0 9
Card 015: 15 16 18 28 47 51 1 10
Card 016: 16 17 19 29 48 52 2 11
Card 017: 17 18 20 30 49 53 3 12
Card 018: 18 19 21 31 50 54 4 13
Card 019: 19 20 22 32 51 55 5 14
Card 020: 20 21 23 33 52 56 6 15
Card 021: 21 22 24 34 53 0 7 16
Card 022: 22 23 25 35 54 1 8 17
Card 023: 23 24 26 36 55 2 9 18
Card 024: 24 25 27 37 56 3 10 19
Card 025: 25 26 28 38 0 4 11 20
Card 026: 26 27 29 39 1 5 12 21
Card 027: 27 28 30 40 2 6 13 22
Card 028: 28 29 31 41 3 7 14 23
Card 029: 29 30 32 42 4 8 15 24
Card 030: 30 31 33 43 5 9 16 25
Card 031: 31 32 34 44 6 10 17 26
Card 032: 32 33 35 45 7 11 18 27
Card 033: 33 34 36 46 8 12 19 28
Card 034: 34 35 37 47 9 13 20 29
Card 035: 35 36 38 48 10 14 21 30
Card 036: 36 37 39 49 11 15 22 31
Card 037: 37 38 40 50 12 16 23 32
Card 038: 38 39 41 51 13 17 24 33
Card 039: 39 40 42 52 14 18 25 34
Card 040: 40 41 43 53 15 19 26 35
Card 041: 41 42 44 54 16 20 27 36
Card 042: 42 43 45 55 17 21 28 37
Card 043: 43 44 46 56 18 22 29 38
Card 044: 44 45 47 0 19 23 30 39
Card 045: 45 46 48 1 20 24 31 40
Card 046: 46 47 49 2 21 25 32 41
Card 047: 47 48 50 3 22 26 33 42
Card 048: 48 49 51 4 23 27 34 43
Card 049: 49 50 52 5 24 28 35 44
Card 050: 50 51 53 6 25 29 36 45
Card 051: 51 52 54 7 26 30 37 46
Card 052: 52 53 55 8 27 31 38 47
Card 053: 53 54 56 9 28 32 39 48
Card 054: 54 55 0 10 29 33 40 49
Card 055: 55 56 1 11 30 34 41 50
Card 056: 56 0 2 12 31 35 42 51
Cards: 73 Order 8:
Card 000: 0 1 3 7 15 31 36 54 63
Card 001: 1 2 4 8 16 32 37 55 64
Card 002: 2 3 5 9 17 33 38 56 65
Card 003: 3 4 6 10 18 34 39 57 66
Card 004: 4 5 7 11 19 35 40 58 67
Card 005: 5 6 8 12 20 36 41 59 68
Card 006: 6 7 9 13 21 37 42 60 69
Card 007: 7 8 10 14 22 38 43 61 70
Card 008: 8 9 11 15 23 39 44 62 71
Card 009: 9 10 12 16 24 40 45 63 72
Card 010: 10 11 13 17 25 41 46 64 0
Card 011: 11 12 14 18 26 42 47 65 1
Card 012: 12 13 15 19 27 43 48 66 2
Card 013: 13 14 16 20 28 44 49 67 3
Card 014: 14 15 17 21 29 45 50 68 4
Card 015: 15 16 18 22 30 46 51 69 5
Card 016: 16 17 19 23 31 47 52 70 6
Card 017: 17 18 20 24 32 48 53 71 7
Card 018: 18 19 21 25 33 49 54 72 8
Card 019: 19 20 22 26 34 50 55 0 9
Card 020: 20 21 23 27 35 51 56 1 10
Card 021: 21 22 24 28 36 52 57 2 11
Card 022: 22 23 25 29 37 53 58 3 12
Card 023: 23 24 26 30 38 54 59 4 13
Card 024: 24 25 27 31 39 55 60 5 14
Card 025: 25 26 28 32 40 56 61 6 15
Card 026: 26 27 29 33 41 57 62 7 16
Card 027: 27 28 30 34 42 58 63 8 17
Card 028: 28 29 31 35 43 59 64 9 18
Card 029: 29 30 32 36 44 60 65 10 19
Card 030: 30 31 33 37 45 61 66 11 20
Card 031: 31 32 34 38 46 62 67 12 21
Card 032: 32 33 35 39 47 63 68 13 22
Card 033: 33 34 36 40 48 64 69 14 23
Card 034: 34 35 37 41 49 65 70 15 24
Card 035: 35 36 38 42 50 66 71 16 25
Card 036: 36 37 39 43 51 67 72 17 26
Card 037: 37 38 40 44 52 68 0 18 27
Card 038: 38 39 41 45 53 69 1 19 28
Card 039: 39 40 42 46 54 70 2 20 29
Card 040: 40 41 43 47 55 71 3 21 30
Card 041: 41 42 44 48 56 72 4 22 31
Card 042: 42 43 45 49 57 0 5 23 32
Card 043: 43 44 46 50 58 1 6 24 33
Card 044: 44 45 47 51 59 2 7 25 34
Card 045: 45 46 48 52 60 3 8 26 35
Card 046: 46 47 49 53 61 4 9 27 36
Card 047: 47 48 50 54 62 5 10 28 37
Card 048: 48 49 51 55 63 6 11 29 38
Card 049: 49 50 52 56 64 7 12 30 39
Card 050: 50 51 53 57 65 8 13 31 40
Card 051: 51 52 54 58 66 9 14 32 41
Card 052: 52 53 55 59 67 10 15 33 42
Card 053: 53 54 56 60 68 11 16 34 43
Card 054: 54 55 57 61 69 12 17 35 44
Card 055: 55 56 58 62 70 13 18 36 45
Card 056: 56 57 59 63 71 14 19 37 46
Card 057: 57 58 60 64 72 15 20 38 47
Card 058: 58 59 61 65 0 16 21 39 48
Card 059: 59 60 62 66 1 17 22 40 49
Card 060: 60 61 63 67 2 18 23 41 50
Card 061: 61 62 64 68 3 19 24 42 51
Card 062: 62 63 65 69 4 20 25 43 52
Card 063: 63 64 66 70 5 21 26 44 53
Card 064: 64 65 67 71 6 22 27 45 54
Card 065: 65 66 68 72 7 23 28 46 55
Card 066: 66 67 69 0 8 24 29 47 56
Card 067: 67 68 70 1 9 25 30 48 57
Card 068: 68 69 71 2 10 26 31 49 58
Card 069: 69 70 72 3 11 27 32 50 59
Card 070: 70 71 0 4 12 28 33 51 60
Card 071: 71 72 1 5 13 29 34 52 61
Card 072: 72 0 2 6 14 30 35 53 62
Cards: 91 Order 9:
Card 000: 0 1 3 9 27 49 56 61 77 81
Card 001: 1 2 4 10 28 50 57 62 78 82
Card 002: 2 3 5 11 29 51 58 63 79 83
Card 003: 3 4 6 12 30 52 59 64 80 84
Card 004: 4 5 7 13 31 53 60 65 81 85
Card 005: 5 6 8 14 32 54 61 66 82 86
Card 006: 6 7 9 15 33 55 62 67 83 87
Card 007: 7 8 10 16 34 56 63 68 84 88
Card 008: 8 9 11 17 35 57 64 69 85 89
Card 009: 9 10 12 18 36 58 65 70 86 90
Card 010: 10 11 13 19 37 59 66 71 87 0
Card 011: 11 12 14 20 38 60 67 72 88 1
Card 012: 12 13 15 21 39 61 68 73 89 2
Card 013: 13 14 16 22 40 62 69 74 90 3
Card 014: 14 15 17 23 41 63 70 75 0 4
Card 015: 15 16 18 24 42 64 71 76 1 5
Card 016: 16 17 19 25 43 65 72 77 2 6
Card 017: 17 18 20 26 44 66 73 78 3 7
Card 018: 18 19 21 27 45 67 74 79 4 8
Card 019: 19 20 22 28 46 68 75 80 5 9
Card 020: 20 21 23 29 47 69 76 81 6 10
Card 021: 21 22 24 30 48 70 77 82 7 11
Card 022: 22 23 25 31 49 71 78 83 8 12
Card 023: 23 24 26 32 50 72 79 84 9 13
Card 024: 24 25 27 33 51 73 80 85 10 14
Card 025: 25 26 28 34 52 74 81 86 11 15
Card 026: 26 27 29 35 53 75 82 87 12 16
Card 027: 27 28 30 36 54 76 83 88 13 17
Card 028: 28 29 31 37 55 77 84 89 14 18
Card 029: 29 30 32 38 56 78 85 90 15 19
Card 030: 30 31 33 39 57 79 86 0 16 20
Card 031: 31 32 34 40 58 80 87 1 17 21
Card 032: 32 33 35 41 59 81 88 2 18 22
Card 033: 33 34 36 42 60 82 89 3 19 23
Card 034: 34 35 37 43 61 83 90 4 20 24
Card 035: 35 36 38 44 62 84 0 5 21 25
Card 036: 36 37 39 45 63 85 1 6 22 26
Card 037: 37 38 40 46 64 86 2 7 23 27
Card 038: 38 39 41 47 65 87 3 8 24 28
Card 039: 39 40 42 48 66 88 4 9 25 29
Card 040: 40 41 43 49 67 89 5 10 26 30
Card 041: 41 42 44 50 68 90 6 11 27 31
Card 042: 42 43 45 51 69 0 7 12 28 32
Card 043: 43 44 46 52 70 1 8 13 29 33
Card 044: 44 45 47 53 71 2 9 14 30 34
Card 045: 45 46 48 54 72 3 10 15 31 35
Card 046: 46 47 49 55 73 4 11 16 32 36
Card 047: 47 48 50 56 74 5 12 17 33 37
Card 048: 48 49 51 57 75 6 13 18 34 38
Card 049: 49 50 52 58 76 7 14 19 35 39
Card 050: 50 51 53 59 77 8 15 20 36 40
Card 051: 51 52 54 60 78 9 16 21 37 41
Card 052: 52 53 55 61 79 10 17 22 38 42
Card 053: 53 54 56 62 80 11 18 23 39 43
Card 054: 54 55 57 63 81 12 19 24 40 44
Card 055: 55 56 58 64 82 13 20 25 41 45
Card 056: 56 57 59 65 83 14 21 26 42 46
Card 057: 57 58 60 66 84 15 22 27 43 47
Card 058: 58 59 61 67 85 16 23 28 44 48
Card 059: 59 60 62 68 86 17 24 29 45 49
Card 060: 60 61 63 69 87 18 25 30 46 50
Card 061: 61 62 64 70 88 19 26 31 47 51
Card 062: 62 63 65 71 89 20 27 32 48 52
Card 063: 63 64 66 72 90 21 28 33 49 53
Card 064: 64 65 67 73 0 22 29 34 50 54
Card 065: 65 66 68 74 1 23 30 35 51 55
Card 066: 66 67 69 75 2 24 31 36 52 56
Card 067: 67 68 70 76 3 25 32 37 53 57
Card 068: 68 69 71 77 4 26 33 38 54 58
Card 069: 69 70 72 78 5 27 34 39 55 59
Card 070: 70 71 73 79 6 28 35 40 56 60
Card 071: 71 72 74 80 7 29 36 41 57 61
Card 072: 72 73 75 81 8 30 37 42 58 62
Card 073: 73 74 76 82 9 31 38 43 59 63
Card 074: 74 75 77 83 10 32 39 44 60 64
Card 075: 75 76 78 84 11 33 40 45 61 65
Card 076: 76 77 79 85 12 34 41 46 62 66
Card 077: 77 78 80 86 13 35 42 47 63 67
Card 078: 78 79 81 87 14 36 43 48 64 68
Card 079: 79 80 82 88 15 37 44 49 65 69
Card 080: 80 81 83 89 16 38 45 50 66 70
Card 081: 81 82 84 90 17 39 46 51 67 71
Card 082: 82 83 85 0 18 40 47 52 68 72
Card 083: 83 84 86 1 19 41 48 53 69 73
Card 084: 84 85 87 2 20 42 49 54 70 74
Card 085: 85 86 88 3 21 43 50 55 71 75
Card 086: 86 87 89 4 22 44 51 56 72 76
Card 087: 87 88 90 5 23 45 52 57 73 77
Card 088: 88 89 0 6 24 46 53 58 74 78
Card 089: 89 90 1 7 25 47 54 59 75 79
Card 090: 90 0 2 8 26 48 55 60 76 80