Implement a rule \"crypto\" that solves the following cryptarithmetic addition p
ID: 3838889 • Letter: I
Question
Implement a rule "crypto" that solves the following cryptarithmetic addition problem in Prolog:
WAIT + ALL = GIFTS
Each of the letters stands for a different digit. The 3 letters (W, A, G) cannot be 0.
The aim is to find a substitution of digits for the letters such that the above stated product is arithmetically correct. The program should find all answers.
It should be possible to query your solution in this manner:
?- crypto(W,A,I,T,L,G,F,S)).
Your solution should then produce all of the combinations of the digits that satisfy the addition problem above.
Make sure you never let W=A, or I=T, etc... all of the distinct letters must stand for distinct digits.
Use generate-and-test!
So far I have this:
digit(9). digit(8). digit(7). digit(6). digit(5). digit(4). digit(3). digit(2). digit(1). digit(0).
crypt(W,A,I,T,L,G,F,S) :-
digit(W), digit(A), digit(I), digit(T), digit(L), digit(G), digit(F), digit(S),
W=0, A=0, G=0, W=A, W=I, W=T, A=I, A=L, G=I, G=F, G=T, I=F, I=T
WAIT is ??
ALL is ??
GIFTS is WAIT + ALL,
ANSW = GIFTS.
I'm not sure how much of that is right though.
Explanation / Answer
the arithmetic way to solve this problem can be wait+all=gifts can be done in the following way
wait can be taken as 9608 and all can be taken as 677
addition of wait+all=9608+677=10285=gifts
We see at once that w in the total must be 9, since the total of the column SM cannot reach as high as 20. Now if M in this column is replaced by 9, how can we make this column total as much as 10 to provide the 1 carried over to the left below? Only by making w very large: 9.
wait+all=gifts
the place of w should have 0 such that the value must be 9 so that the carry will be 1. and the next highest number must be 8 which has been replaced by t the next highest element than w. in the following way t+l=15 which will give 1 as carry.
a value cannot be 2 because the value of w is 10 where 1 is taken as carry.
here atmost the repeating a;phabets should not be taken then the value for
where the value of wait=9608 and all=677 hence the total will be 10285
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.