在初学者课程中,我们被要求在 Prolog 中做一些经典的密码。它们都可以工作,除了这个,它只是继续下去,没有找到任何解决方案,除了试图让我的电脑因过热而炸毁:
四十 + 十 + 十 = 六十
crypto2(F,O,R,T,Y,E,N,S,I,X) :-
digit(F), digit(O), digit(R), digit(T), digit(Y), digit(E), digit(N), digit(S), digit(I), digit(X),
F =\= O, F =\= R, F =\= T, F =\= Y, F =\= E, F =\= N, F =\= S, F =\= I, F =\= X,
O =\= R, O =\= T, O =\= Y, O =\= E, O =\= N, O =\= S, O =\= I, O =\= X,
R =\= T, R =\= Y, R =\= E, R =\= N, R =\= S, R =\= I, R =\= X,
T =\= Y, T =\= E, T =\= N, T =\= S, T =\= I, T =\= X,
Y =\= E, Y =\= N, Y =\= S, Y =\= I, Y =\= X,
E =\= N, E =\= S, E =\= I, E =\= X,
N =\= S, N =\= I, N =\= X,
S =\= I, S =\= X,
I =\= X,
10000 * F + 1000 * O + 100 * R + 210 * T + Y + 20 * E + 2 * N =:= 10000 * S + 1000 * I + 100 * X + 10 * T + Y.
所有数字到数字的不等式都是用这个 python 编写的,以防止人为错误:
nbs = ["F", "O", "R", "T", "Y", "E", "N", "S", "I", "X"]
for i in range(len(nbs)):
s= ""
for j in range(i + 1, len(nbs)):
s += nbs[i] + " =\= " + nbs[j] + ", "
print s
这里没有写的是一系列十个简单的事实(数字(0)。到数字(9)。)断言0-9是数字。
有人能发现一个明显的错误吗,或者真的需要十多分钟,而更简单的六位数密码可以立即解决?
谢谢!