2.2. Introductory TOY(FD) Examples 27
C #+ E #+ L #+ L #+ O #= 43,
C #+ O #+ N #+ C #+ E #+ R #+ T #= 74,
F #+ L #+ U #+ T #+ E #= 30,
F #+ U #+ G #+ U #+ E #= 50,
G #+ L #+ E #+ E #= 66,
J #+ A #+ Z #+ Z #= 58,
L #+ Y #+ R #+ E #= 47,
O #+ B #+ O #+ E #= 53,
O #+ P #+ E #+ R #+ A #= 65,
P #+ O #+ L #+ K #+ A #= 59,
Q #+ U #+ A #+ R #+ T #+ E #+ T #= 50,
S #+ A #+ X #+ O #+ P #+ H #+ O #+ N #+ E #= 134,
S #+ C #+ A #+ L #+ E #= 51,
S #+ O #+ L #+ O #= 37,
S #+ O #+ N #+ G #= 61,
S #+ O #+ P #+ R #+ A #+ N #+ O #= 82,
T #+ H #+ E #+ M #+ E #= 72,
V #+ I #+ O #+ L #+ I #+ N #= 100,
W #+ A #+ L #+ T #+ Z #= 34,
labeling Label LD
Solving in the command level is shown below:
TOY(FD)> alpha [ff] L
yes
L==[5,13,9,16,20,4,24,21,25,17,23,2,8,12,10,19,7,11,15,3,1,26,6,22,14,18]
Elapsed time: 9735 ms.
2.2.4 Magic Sequences
We present another simple (and well-known) example, the magic series problem Van Hen-
tenryck, 1989. Let S = (s
0
, s
1
, . . . , s
N−1
) be a non-empty finite serial of non-negative
integers. As convention, we number its elements from 0. The serial S is said N-magic
if and only if there are s
i
occurrences of i in S, for all i in {1, . . . , N − 1}.
Below we show a possible TOY(FD) solution, included in the distribution in the
directory Examples in the file magicseq.toy, to this problem.
include "cflpfd.toy"
include "misc.toy" %% To use length/1
magic :: int -> [int] -> [labelingType] -> bool
magic N L Label = true <==
length L == N,
domain L 0 (N-1), % Functional syntax (N-1)
Comentarios a estos manuales