Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4. Here's a cryptarithmetic problem published in 1933 in a journal
- called "Sphinx":
- S E P T E M B R E
- - E R B M E T P E S
- -------------------
- M P P B R P S S M
- Use generate-and-test. An appropriate query would be of the form:
- ?- crypto(S,E,P,T,M,B,R).
- which would return assignments for S,E,P,etc that make the math correct.
- Make sure you never let S=E, or P=T, etc... all of the
- distinct letters have to stand for distinct digits.
- It might run slowly!
- crypto(S,E,P,T,M,B,R) :-
- % Every letter must be a valid digit.
- digit(S), digit(E), digit(P), digit(T), digit(M), digit(B), digit(R),
- % No digit can equal any other digit.
- S \= E, S \= P, S \= T, S \= M, S \= B, S \= R,
- E \= P, E \= T, E \= M, E \= B, E \= R,
- P \= T, P \= M, P \= B, P \= R,
- T \= M, T \= B, T \= R,
- M \= B, M \= R,
- B \= R,
- Minuend is S*10^8 + E*10^7 + P*10^6 + T*10^5 + E*10^4 + M*10^3 + B*10^2 + R*10 + E,
- Subtrahend is E*10^8 + R*10^7 + B*10^6 + M*10^5 + E*10^4 + T*10^3 + P*10^2 + E*10 + S,
- Difference is Minuend - Subtrahend,
- Expected is M*10^8 + P*10^7 + P*10^6 + B*10^5 + R*10^4 + P*10^3 + S*10^2 + S*10 + M,
- Difference = Expected.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement