-1

I have the following task in Prolog:

Find an assignment of the letters to digits (each letter to a different digit) so that the following product holds:

EAU * EAU = OCEAN

If the code for this is as follows:

:- use_module(library(clpfd)).

ocean(L) :-
   L = [O,C,E,A,N],
   L2 = [U|L],
   all_different(L2),
   L2 ins 0..9,
   EAU #= E*100 + A*10 + U,
   OCEAN #= O*10000 + C * 1000 + E*100 + A*10 + N,
   EAU * EAU #= OCEAN,
   labeling([], L2).

Can someone please explain the following:

What is the meaning of L2 ins 0..9 (Why is the range between these numbers?)

What is the meaning of multiplying the letters by these particular numbers *10000 + C * 1000 + E*100, and E*100 + A*10 + U etc.?

Many thanks in advance for any guidance provided.

false
  • 10,264
  • 13
  • 101
  • 209
CompilerSaysNo
  • 415
  • 3
  • 14
  • You should take a look at this page http://www.swi-prolog.org/man/clpfd.html to understand the code (and may be fix it) ! – joel76 May 27 '14 at 09:11
  • 1
    [Base 10 Number System](http://www.studyzone.org/testprep/math4/d/baseten4l.cfm) – lurker May 27 '14 at 12:25

1 Answers1

1

'0..9' just means a single digit: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.

EAU #= E*100 + A*10 + U is for indication that a number 'EAU' consist of digits 'E', 'A' and 'U' in that particular order. For example, if you have a number 735 = 7*100 + 3*10 + 5.

Similarly for 'OCEAN', a five-digit number.

Also, constraints in the program you provided look incomplete to me. It should also be stated that the first digit of every number is greater than 0, because usually we don't use numbers with leading zeros like '0123'.

Sergii Dymchenko
  • 6,890
  • 1
  • 21
  • 46