1

I have problems with my CSP under ECLiPSe. I wish to add a constraint to my cryptogram which requires that the number represented by TWO is divisible by 2.

[eclipse 11]: test(Xs).
instantiation fault in (_268{[1..4]}*100 + _200{[0..9]}*10 + _302{[0..9]}*1) mod 2#=0
Abort

Thanks for your help.

My code :

/*
          T W O                                           
   +  T H R E E      
   +  T H R E E                                       
      ---------                                      
      E I G H T                                     
*/

:- lib(fd).

myCsp(Xs):-
    Xs=[W,I,G,H,T,R,O,E],
    Xs::0..9,
    [C1,C2,C3,C4]::0..2,
    T #> 0,E #> 0,
    O + E + E #= C1*10 + T,
    W + E + E + C1 #= C2*10 + H,
    T + R + R + C2 #= C3*10 + G,
    H + H + C3 #= C4*10 + I,
    T + T + C4 #= E,
    (T*100 + W*10 + O*1) mod 2 #= 0,
    alldifferent([W,I,G,H,T,R,O,E]).

test(Xs):-
    myCsp(Xs),
    labeling(Xs).
false
  • 10,264
  • 13
  • 101
  • 209
superyo40
  • 75
  • 7
  • Why are you using `(is)/2`? Use the CLP(FD) constraint `(#=)/2` for expressing equality of integer expressions! – mat Feb 25 '16 at 19:29
  • Thank you ! I replace `myModulo2(T,W,O),` to `T*100 + W*10 + O*1 #=/2,` in myCsp. But now i have a syntaxe error : #=/2 postfix/infix operator expected ?? – superyo40 Feb 25 '16 at 19:50
  • 1
    Oh come on! You are already using `(#=)/2` in other places of your program (hint: it is the most frequently used predicate in your snippet). Just use it in the remaining two places too! – mat Feb 25 '16 at 19:52
  • I just change my code but still the same problem. I must be stupid :) – superyo40 Feb 25 '16 at 20:06

1 Answers1

5

The mod/2 operation in

(T*100 + W*10 + O*1) mod 2 #= 0

isn't supported. You can rewrite the line as

T*100 + W*10 + O*1  #=  2*_

which says that the left hand side expression is equal to twice an anonymous integer variable, and thus a multiple of two.

jschimpf
  • 4,904
  • 11
  • 24