4.4 Another drawback of our program is that it only solves the particular puzzle DONALD + GERALD...

Question:

4.4 Another drawback of our program is that it only solves the particular puzzle DONALD + GERALD = ROBERT. But to solve another famous puzzle SEND + MORE MONEY, we would have to write another program. Of course, we can just modify the variables list and the arithmetic condition in the program. It would be more elegant, however, if our program would be more general, and capable of solving any puzzle, whereby the required arithmetic condition would be specified in the Prolog query. One way of doing this is to introduce three additional arguments to our main predicate - three lists representing the three numbers. So the main predicate would be, say, puzzle( Letters, List1, List2, List3)

Then the question for DONALD + GERALD = ROBERT would be: ? L1 = [D,O,N,A,L,D), L2 = [G,E,R,A,L,D), L3 = [R,O,B,E,R,T], puzzle([D,O,N,A,L,G,E,R,B,T], L1, L2, L3). Or a question for SEND + MORE MONEY would be: = ?- L1 = [0,S,E,N,D], L2 = [0,M,O,R,E], L3 = [M,O,N,E,Y], puzzle([S,E,N,D,M,O,R,Y], L1, L2, L3). Define the predicate puzzle. An idea: Introduce an auxiliary predicate list_number (Digits, N) where Digits is a list of decimal digits that represents a number, and N is the number represented by Digits. For example: list_number([1,4,3], 143).

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: