26 CHAPTER 2. TOY(FD) Programming Examples
Elapsed time: 0 ms.
more solutions (y/n/d) [y]? ; %% Do not look for more solutions
TOY(FD)>
2.2.3 A Cryptoarithmetic Problem
Alpha is a cryptoarithmetic problem where the numbers 1 - 26 are randomly assigned
to the letters of the alphabet. The numbers beside each word are the total of the
values assigned to the letters in the word. e.g for LYRE L,Y,R,E might equal 5,9,20
and 13 respectively or any other combination that add up to 47. The problem consists
of finding the value of each letter under the following equations:
BALLET = 45,
GLEE = 66,
POLKA = 59,
SONG = 61,
CELLO = 43,
JAZZ = 58,
QUARTET = 50,
SOPRANO = 82,
CONCERT = 74
LYRE = 47,
SAXOPHONE = 134,
THEME = 72,
FLUTE = 30,
OBOE = 53,
SCALE = 51,
VIOLIN = 100,
FUGUE = 50,
OPERA = 65,
SOLO = 37,
WALTZ = 34
A TOY(FD) solution, included in the distribution in the directory Examples in the
file alpha.toy, is shown below:
include "cflpfd.toy"
alpha :: [labelingType] -> [int] -> bool
alpha Label LD = true <==
LD == [A,B,C,_D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z],
domain LD 1 26,
all_different LD,
B #+ A #+ L #+ L #+ E #+ T #= 45,
Comentários a estes Manuais