/* Self-referential sentence in Picat. E.g. from http://puzzling.stackexchange.com/questions/1901/write-a-true-self-reflective-statement-about-the-digits-from-0-to-9-or-prove-it http://puzzling.stackexchange.com/questions/1904/what-is-smallest-n-to-complite-the-task-write-a-true-self-reflective-statement "This statement contains 1 0's, 7 1's, 3 2's, 2 3's, 1 4's, 1 5's, 1 6's, 2 7's, 1 8's, and 1 9's." Note: It happens that the number of occurrences are between 1..9 so we don't have to worry about converting 10 to [1,0] etc. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go => ref(9,_), nl. go2 => Counts = [], foreach(N in 1..9) println(n=N), ( ref(N,C) , Counts := Counts ++ [N=C] ; true ) end, println(counts=Counts), nl. % % General solution for 0..N (N <= 9) % (There are no solutions for N=1,2,5.) % ref(N,Counts) => N1 = N+1, N2 = N1*2, Ref = new_list(N2), Ref :: 0..N, foreach(I in 0..N) Ref[I*2+1] #= I, % the digits Ref[I*2+2] #= sum([S#=I : S in Ref]) % number of occurrences of digit I end, solve(Ref), println(ref=[[Ref[I*2+1],Ref[I*2+2]] : I in 0..N]), String = "This statement contains " ++ [Ref[I*2+2].to_string() ++ " " ++ Ref[I*2+1].to_string() ++ "'s, " ++ cond(I == N-1, "and ", "") : I in 0..N].flatten(), println(String), Counts = [Ref[I*2+2] : I in 0..N], nl.