Files
mercury/tests/term/money.m
Zoltan Somogyi 9cacd33f47 Remove "is" as a synonym for "=", step 1.
This first step deals with the consequences of such removal.
The removal itself will happen in stage 2. That step will
add "is" to the prolog module in the library.

compiler/add_pred.m:
    Prepare for "is" being in the prolog module.

compiler/options.m:
    Add a way to test whether the change to add_pred.m is in the
    installed compiler.

tests/accumulator/base.m:
tests/accumulator/call_in_base.m:
tests/accumulator/chain.m:
tests/accumulator/commutative.m:
tests/accumulator/construct_test.m:
tests/accumulator/dcg.m:
tests/accumulator/deconstruct_test.m:
tests/accumulator/disj.m:
tests/accumulator/func.m:
tests/accumulator/heuristic.m:
tests/accumulator/highorder.m:
tests/accumulator/identity.m:
tests/accumulator/inter.m:
tests/accumulator/nonrec.m:
tests/accumulator/out_to_in.m:
tests/accumulator/qsort.m:
tests/accumulator/simple.m:
tests/accumulator/split.m:
tests/accumulator/swap.m:
tests/benchmarks/cqueens.m:
tests/benchmarks/crypt.m:
tests/benchmarks/deriv.m:
tests/benchmarks/deriv2.m:
tests/benchmarks/nrev.m:
tests/benchmarks/poly.m:
tests/benchmarks/primes.m:
tests/benchmarks/qsort.m:
tests/benchmarks/query.m:
tests/benchmarks/tak.m:
tests/debugger/interactive.m:
tests/declarative_debugger/Mercury.options:
tests/declarative_debugger/io_read_bug.m:
tests/declarative_debugger/queens.exp:
tests/declarative_debugger/queens.m:
tests/dppd/imperative_solve_impl.m:
tests/dppd/map_impl.m:
tests/dppd/max_length_impl.m:
tests/dppd/sum.m:
tests/dppd/upto_sum_impl.m:
tests/par_conj/dep_par_21.m:
tests/tabling/seq.m:
tests/term/dds3_14.m:
tests/term/mmatrix.m:
tests/term/money.m:
tests/term/occur.m:
tests/term/pl4_5_2.m:
tests/term/queens.m:
tests/typeclasses/inference_test.m:
tests/typeclasses/inference_test_2.m:
tests/valid/lazy_list.m:
tests/warnings/duplicate_const.m:
    Replace calls to "is" with unifications. In many places,
    bring programming style up to date.
2020-08-21 10:42:37 +10:00

93 lines
1.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Program: Cryptarithmetic puzzle SENDMORY
% Author: Rong Yang (adapted)
% Date:
%
% Notes:
% 1. To run:
% ?- money(S, E, N, D, M, O, R, Y).
% 2. Solution is reached in the domain approach so as to recognize determinism
% as the ecuations are being resolved.
% 3. After-checks are used and calc/5 ordering is better (L to R).
% compiled it takes about 50 sec.
%
:- module money.
:- interface.
:- type list(T)
---> []
; [T | list(T)].
:- pred solve(list(int)::out) is nondet.
:- implementation.
:- import_module int.
:- import_module prolog.
solve([S, E, N, D, M, O, R, Y]) :-
money(S, E, N, D, M, O, R, Y).
:- pred money(int, int, int, int, int, int, int, int).
:- mode money(out, out, out, out, out, out, out, out).
money(S, E, N, D, M, O, R, Y) :-
carry(C1),
carry(C2),
carry(C3),
carry(C4),
C4 = M,
M \= 0,
domain([S, E, N, D, M, O, R, Y], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
S \= 0,
calc(C3, S, M, C4, O),
calc(C2, E, O, C3, N),
calc(C1, N, R, C2, E),
calc( 0, D, E, C1, Y).
:- pred calc(int, int, int, int, int).
:- mode calc(in, in, in, in, in).
calc(C0, D, E, C1, Y) :-
sum(C0, D, CD),
sum(CD, E, S),
carry10(C1, C10),
sum(C10, Y, S).
:- pred sum(int, int, int).
:- mode sum(in, in, out).
sum(X, Y, Z) :-
Z = X + Y.
:- pred domain(list(T), list(T)).
:- mode domain(out, in).
domain([], _).
domain([X1 | R], L) :-
del(X1, L, NL),
domain(R, NL).
:- pred del(T, list(T), list(T)).
:- mode del(out, in, out).
del(X, [X | T], T).
del(X, [Y | T], [Y | NT]) :-
del(X, T, NT).
:- pred carry(int).
:- mode carry(out).
carry(1).
carry(0).
:- pred carry10(int, int).
:- mode carry10(in, out).
carry10(0, 0).
carry10(1, 10).