/* Number of fix points in Picat. A fix point is - here - when the I'th element is assigned to I, i.e. X[I] #= I It can, for example, be used together with subcircuit to constraint the of solutions. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 7, X = new_list(N), X :: 1..N, Z :: 0..N, % number of fixpoints in x fix_points(Z, X), Z #= 4, Vars = X ++ [Z], solve(Vars), println(x=X), println(z=Z), nl, fail, nl. go => true. % % Also using subcircuit % go2 ?=> N = 7, X = new_list(N), X :: 1..N, Z :: 0..N, % number of fixpoints in x fix_points(Z, X), Z #= 6, Vars = X ++ [Z], solve(Vars), println(x=X), println(z=Z), nl, fail, nl. go2 => true. % % A is the number of fix_points in the list X % fix_points(A, X) => A #= sum([X[I] #= I : I in 1..X.len]).