[mercury-users] Doing something with all solutions
nik9000 at gmail.com
Thu Jul 19 09:41:34 AEST 2007
I'm sure you get this a lot, but how can I ask Mercury to do something with
all the solutions that it finds for some predicate? At this point I'd just
like to print out all of my solutions, but I'm sure there are better things
to do then that.
I've started with one of the programs in the Ralph Becket's tutorial and
produced the below. I've messed around a little with the solutions module,
but haven't gotten any where.
Thanks in advance, and sorry to bother the list with what feels like a
newbie question. If answers to questions like these can be found somewhere,
please let me know where to look.
:- module first.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- import_module int, list, string.
io.format("DOG + ANT = CAT\n", , !IO),
dogAntCat(DOG, ANT, CAT)
io.format("%d + %d = %d\n", [i(DOG), i(ANT), i(CAT)], !IO)
io.format("No result.", , !IO)
:- pred dogAntCat(int::out, int::out, int::out) is nondet.
dogAntCat(DOG, ANT, CAT) :-
D0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], C0 = 0,
pick(D0, G, D1),
pick(D1, T, D2),
T = (G + T + C0) mod 10, C1 = (G + T + C0) / 10,
pick(D2, O, D3),
pick(D3, N, D4),
A = (O + N + C1) mod 10, A\=0, C2 = (O + N + C1) / 10,
pick(D4, D, D5),
pick(D5, A, D6),
C = (D + A + C2), D \= 0, 0 = (D + A + C2) / 10,
pick(D6, C, _)
DOG = 100 * D + 10 * O + G,
ANT = 100 * A + 10 * N + T,
CAT = 100 * C + 10 * A + T
:- pred pick(list(int)::in, int::out, list(int)::out) is nondet.
pick([X | Xs], X, Xs).
pick([X | Xs], Y, [X | Zs]) :- pick(Xs, Y, Zs).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the users