在初学者课程中,我们被要求在Prolog中做一些经典的密码学。他们都工作,除了这一个,只是继续下去而没有找到任何解决方案,除了试图让我的电脑因过热而爆炸:
FORTY + TEN + TEN = SIXTY
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是数字。
有人可以发现一个明显的错误,或者它真的需要超过十分钟,而更简单的六位数密码会立即解决吗?
谢谢!
答案 0 :(得分:2)
你可以把事情稍微移动约束'第一可能':
crypto2(F,O,R,T,Y,E,N,S,I,X) :-
digit(F),
digit(O), F =\= O,
digit(R), F =\= R, O =\= R,
digit(T), F =\= T, ...