Skip to content

Instantly share code, notes, and snippets.

@Syncrossus
Last active July 3, 2018 09:58
Show Gist options
  • Save Syncrossus/2ada0f39957d7e13bf91ae71750e1428 to your computer and use it in GitHub Desktop.
Save Syncrossus/2ada0f39957d7e13bf91ae71750e1428 to your computer and use it in GitHub Desktop.
Solution to the problem WWWDOT - GOOGLE = DOTCOM (GLAT question 1) in prolog
% solution to the problem WWWDOT - GOOGLE = DOTCOM in prolog
carry(0).
carry(1).
digit(A) :- carry(A).
digit(2).
digit(3).
digit(4).
digit(5).
digit(6).
digit(7).
digit(8).
digit(9).
solve(W,D,O,T,G,L,E,C,M):-
carry(ALPHA),
carry(BETA),
carry(GAMMA),
carry(DELTA),
carry(EPSILON),
digit(T),
digit(E),
T \== E,
digit(M),
T \== M,
E \== M,
(T+10*ALPHA) - E =:= M,
digit(O),
T \== O,
E \== O,
M \== O,
digit(L),
T \== L,
E \== L,
M \== L,
O \== L,
(O-ALPHA+10*BETA) - L =:= O,
digit(W),
T \== W,
E \== W,
M \== W,
O \== W,
L \== W,
(W-GAMMA+10*DELTA) - O =:= T,
(W-DELTA+10*EPSILON) - O =:= O,
digit(D),
T \== D,
E \== D,
M \== D,
O \== D,
L \== D,
W \== D,
digit(G),
T \== G,
E \== G,
M \== G,
O \== G,
L \== G,
W \== G,
D \== G,
digit(C),
T \== C,
E \== C,
M \== C,
O \== C,
L \== C,
W \== C,
D \== C,
G \== C,
(D-BETA+10*GAMMA) - G =:= C,
(W-EPSILON) - G =:= D.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment