Magic sequence in SICStus Prolog.
A magic sequence of length n is a sequence of integers x0 . . xn-1
between 0 and n-1, such that for all i in 0 to n-1, the number i
occurs exactly xi times in the sequence.
For instance, 6,2,1,0,0,0,1,0,0,0 is a magic sequence since 0 occurs
6 times in it, 1 occurs twice, ...
Compare with the following models:
* MiniZinc: http://www.hakank.org/minizinc/magic_sequence.mzn
* Comet : http://www.hakank.org/comet/magic_sequence.co
Also, in the SICStus Prolog distribution there is a model
Model created by Hakan Kjellerstrand, firstname.lastname@example.org
See also my SICStus Prolog page: http://www.hakank.org/sicstus/
% Licenced under CC-BY-4.0 : http://creativecommons.org/licenses/by/4.0/
N = 123,
% Note: after I wrote this I realized that count/4 is
% deprecated in version 4.1.
magic_sequence(N, Seq) :-
N1 is N-1,