0

I need the output to be in the format below. I have the exact output except the last line, and I cannot figure out how to add the last line to the output. I would appreciate any help.

Output

    A = 2,
    M = 5,
    P = 9,
    D = 1,
    Y = 0,
    [2,5]+[9,5]=[1,2,0];

Code

    :- use_module(library(clpfd)).
    puzzle([A,M] + [P,M] = [D,A,Y]) :-
              Vars = [A,P,M,D,Y],
              Vars ins 0..9,
              all_different(Vars),
              A*10 + M + P*10 + M #= D*100 + A*10 + Y,
              A #\= 0,P #\= 0, D #\= 0,
              label([A,P,M,D,Y]).
false
  • 10,264
  • 13
  • 101
  • 209
Rob
  • 1
  • 3
  • You can just do `write('['),write(A),write(','),write(M),` and so on. – Tomas By Mar 31 '18 at 18:41
  • Will that line go on the last line of the program? – Rob Mar 31 '18 at 18:46
  • Yes, you could add `writeln([A,M] + [P,M] = [D,A,Y])` as the last goal in the program, i.e., after the labeling. But it won't do *exactly* what you ask; exactly what you ask is impossible. What you call "output" are variable substitutions printed by the Prolog toplevel. These always have the form "*variable* = *term*", and `[2,5] + [9,5]` is *not* a variable, so it will never appear on the left-hand-side of such a thing. The solution with `writeln` does output such a line, but it's an output in the standard I/O sense; it doesn't mix very cleanly with answer substitutions. – Isabelle Newbie Mar 31 '18 at 19:34

0 Answers0