Problema di criptoaritmetica: listato base

Per una descrizione del problema si veda l’articolo Intelligenza artificiale: un assaggio.

 cifra(0). cifra(1). cifra(2). cifra(3). cifra(4). cifra(5). cifra(6). cifra(7). cifra(8). cifra(9).  risolvi(A,B,C):- 	soluzione(A,B,C).   soluzione(A,B,C) :-                /* nessun riporto - solo D+S */ 	cifra(D), 	cifra(U), 	cifra(E), 	cifra(S), 	cifra(I), 	cifra(O), 	cifra(T),         O is E + I, 	T is U + E, 	T is D + S - 10 + 1, 	O is 1,         diversi(D,U,E,S,I,O,T), 	A is D*100+U*10+E, 	B is S*100+E*10+I, 	C is O*1000 + T*100 + T*10 +O, 	write(A), 	write(B), 	write(C).   soluzione(A,B,C) :-                /* riporto colonna unità e D+S*/ 	cifra(D), 	cifra(U), 	cifra(E), 	cifra(S), 	cifra(I), 	cifra(O), 	cifra(T),         O is E + I - 10, 	T is U + E + 1, 	T is D + S - 10, 	O is 1, 	diversi(D,U,E,S,I,O,T), 	A is D*100+U*10+E, 	B is S*100+E*10+I, 	C is O*1000 + T*100 + T*10 + O, 	write(A), 	write(B), 	write(C).    soluzione(A,B,C) :-                /* riporto colonna decine e D+S */ 	cifra(D), 	cifra(U), 	cifra(E), 	cifra(S), 	cifra(I), 	cifra(O), 	cifra(T),         O is E + I, 	T is U + E, 	T is D + S - 10, 	O is 1, 	diversi(D,U,E,S,I,O,T), 	A is D*100+U*10+E, 	B is S*100+E*10+I, 	C is O*1000 + T*100 + T*10 +O, 	write(A), 	write(B), 	write(C).  soluzione(A,B,C) :-                /* riporto colonne decine e unità e D+S */ 	cifra(D), 	cifra(U), 	cifra(E), 	cifra(S), 	cifra(I), 	cifra(O), 	cifra(T),         O is E + I - 10, 	T is U + E + 1 - 10, 	T is D + S - 10 + 1, 	O is 1, 	diversi(D,U,E,S,I,O,T), 	A is D*100+U*10+E, 	B is S*100+E*10+I, 	C is O*1000 + T*100 + T*10 +O, 	write(A), 	write(B), 	write(C).  diversi(D,U,E,S,I,O,T):- 	D =\= U,         D =\= E, 	D =\= S, 	D =\= I, 	D =\= O, 	D =\= T,         U =\= E, 	U =\= S, 	U =\= I, 	U =\= O, 	U =\= T, 	E =\= S, 	E =\= I, 	E =\= O, 	E =\= T, 	S =\= I, 	S =\= O, 	S =\= T, 	I =\= O, 	I =\= T, 	O =\= T. 

Commenti

commenti