Lösung zum Raetsel21


Lösung in Prolog zum Raetsel21

21_eigenes_raetsel.pl
/* Andreas Tobola, 2008       */
/* GEC   -   ED    =   II     */
/*  =                  *      */
/* GHB   -   ID    =   GA     */
/*  +                   =     */
/* AB    *   CC    =   GGKK   */


probiere(A,B,C,D,E,G,H,I,K,X):-permutation([A,B,C,D,E,G,H,I,K,X],[0,1,2,3,4,5,6,7,8,9]).

gl1(G,E,C,D,I):-((G*100 + E*10 + C) - (E *10 + D)) =:= (I*10 + I).
gl2(G,H,B,I,D,A):-(G*100 + H*10 + B - I*10 - D) =:= (G*10 + A).
gl3(A,B,C,G,K):-((A*10 + B) * (C*10 + C)) =:= (G*1000 + G*100 + K*10 + K).
gl4(G,E,C,H,B,A):-(G*100 + E*10 + C) =:= (G*100 + H*10 + B + A*10 + B).
gl5(I,G,A,K):-((I*10 +I) * (G*10 +A)) =:= (G*1000 + G*100 + K*10 + K).

run:-
probiere(A,B,C,D,E,G,H,I,K,X),
gl1(G,E,C,D,I),
gl2(G,H,B,I,D,A),
gl3(A,B,C,G,K),
gl4(G,E,C,H,B,A),
gl5(I,G,A,K),
nl,
write('A = '),write(A),nl,
write('B = '),write(B),nl,
write('C = '),write(C),nl,
write('D = '),write(D),nl,
write('E = '),write(E),nl,
write('G = '),write(G),nl,
write('H = '),write(H),nl,
write('I = '),write(I),nl,
write('K = '),write(K),nl,
nl,
write('Die Ziffer '), write(X), write(' kommt nicht vor.').




Ausgabe
A = 2
B = 7
C = 4
D = 5
E = 3
G = 1
H = 0
I = 9
K = 8

Die Ziffer 6 kommt nicht vor.




Benchmark:
32,3 Sekunden auf einen Pentium III, 667 MHz, Debian Linux unter GNU-Prolog
20,9 Sekunden auf einen Centrino 1,3 GHz, Windows XP unter SWI-Prolog



Siehe auch Raetsel21

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki