home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / SMM.LF < prev    next >
Text File  |  1996-06-04  |  2KB  |  59 lines

  1.                                                                                                                                                                                                                                                                                                                                                                                                            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.  
  3. smm :-
  4.         % Solutions where M=0 are uninteresting.
  5.  
  6.         M={1;2;3;4;5;6;7;8;9},
  7.  
  8.         % The arithmetic constraints:
  9.  
  10.         C3 + S + M = O + 10*M,
  11.         C2 + E + O = N + 10*C3,
  12.         C1 + N + R = E + 10*C2,
  13.              D + E = Y + 10*C1,
  14.  
  15.         % The all-distinct constraints
  16.  
  17.         diff_list([S,E,N,D,M,O,R,Y]),
  18.  
  19.         % Generating binary digits:
  20.  
  21.         C1=carry,
  22.         C2=carry,
  23.         C3=carry,
  24.  
  25.         % Generating decimal digits:
  26.  
  27.         S=decimal,
  28.         E=decimal,
  29.         N=decimal,
  30.         D=decimal,
  31.         O=decimal,
  32.         R=decimal,
  33.         Y=decimal,
  34.  
  35.         % Print the result:
  36.     nl,
  37.         write(' SEND     ',S,E,N,D),nl,
  38.         write('+MORE    +',M,O,R,E),nl,
  39.         write('-----    -----'),nl,
  40.         write('MONEY    ',M,O,N,E,Y),nl,
  41.         nl.
  42.  
  43.    
  44.  
  45. decimal -> {0;1;2;3;4;5;6;7;8;9}.
  46. carry -> {0;1}.
  47.  
  48.  
  49. diff_list([]).
  50. diff_list([H|T]) :-
  51.         generate_diffs(H,T),
  52.         diff_list(T),
  53.         (H=<9)=true,
  54.         (H>=0)=true.
  55.  
  56. generate_diffs(H,[]).
  57. generate_diffs(H,[A|T]) :-
  58.         generate_diffs(H,T),
  59.         (A =\= H)=true.