/* Relative sizes puzzle (Enigma 1515) in Picat. From http://www.f1compiler.com/samples/Enigma%201515.f1.html """ Enigma 1515 Albert Hadded, New Scientist magazine, October 11, 2008. In the following statements, whole numbers are expressed in words written in capital letters, where different letters stand for different digits, the same letter consistently stands for the same digit, and leading digits cannot be zero. If the total of four BEES and a SNAIL is greater than the total of eight FLEAS and an ANT; and if the total of 18 ANTS and a GNAT is greater than the total of 18 FLIES and a FLEA, find the value of BEETLES. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => Digits = [A,B,E,F,G,I,L,N,S,T], Digits :: 0..9, all_different(Digits), Bees #= B*1000+E*100+E*10+S, B #!= 0, Snail #= S*10000+N*1000+A*100+I*10+L, S #!= 0, Fleas #= F*10000+L*1000+E*100+A*10+S, F #!= 0, Ant #= A*100+N*10+T, A #!= 0, 4*Bees + Snail #> 8*Fleas + Ant, Ants #= A*1000+N*100+T*10+S, A #!= 0, Gnat #= G*1000+N*100+A*10+T, G #!= 0, Flies #= F*10000+L*1000+I*100+E*10+S, F #!= 0, Flea #= F*1000+L*100+E*10+A, F #!= 0, 18*Ants + Gnat #> 18*Flies + Flea, Beetles #= B*1000000+E*100000+E*10000+T*1000+L*100+E*10+S, solve(Digits), println(digits=Digits), println(beetles=Beetles), fail, nl.