/* Four digit palindrome in Picat. https://ai.ia.agh.edu.pl/_media/pl:dydaktyka:est:essential_thinking_2020-59.pdf """ Four Digit Palindroma - four digit palindrom: 1221, 7337, 2992,... - observe: 1221:11=111, 7337:11=667, 2992:11=272,... Hypothesis: Every four-digit palindrom number is divisible by 11. """ page 26 * go/0: Some of the 90 solutions for N=4: n = 4 x = [1,0,0,1] x = [1,1,1,1] x = [1,2,2,1] x = [1,3,3,1] x = [1,4,4,1] x = [1,5,5,1] x = [1,6,6,1] x = [1,7,7,1] x = [1,8,8,1] x = [1,9,9,1] x = [2,0,0,2] x = [2,1,1,2] x = [2,2,2,2] x = [2,3,3,2] ... x = [9,3,3,9] x = [9,4,4,9] x = [9,5,5,9] x = [9,6,6,9] x = [9,7,7,9] x = [9,8,8,9] x = [9,9,9,9] * go2/0: Number of solutions when X mod 11 = 0, for N=2..14: 2 = 9 3 = 8 4 = 90 5 = 82 6 = 900 7 = 818 8 = 9000 9 = 8182 10 = 90000 11 = 81818 12 = 900000 13 = 818182 14 = 9000000 * go3/0: Number of solutions when X mod 11 != 0, for N=2..14. It seems that the hypothesis holds for all even N (see go3/0) but not for odd N. 2 = 0 3 = 82 4 = 0 5 = 818 6 = 0 7 = 8182 8 = 0 9 = 81818 10 = 0 11 = 818182 12 = 0 13 = 8181818 14 = 0 15 = 81818182 16 = 0 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. % % Checking when mod 11 = 0: 90 solutions for n=4 % go ?=> % N = 4, member(N,2..10), println(n=N), Mod #= 0, palindrome(N,Mod,X), solve(X), println(x=X), fail, nl. go => true. % % Checking when mod 11 = 0 for N=2..15. % go2 ?=> member(N,2..14), Mod #= 0, Count = count_all(palindrome(N,Mod,_X)), println(N=Count), fail, nl. go2 => true. % % Checking when mod 11 > 0: 0 solutions for n=4. % See above for the general result, N=2..15. % go3 ?=> member(N,2..14), Mod #> 0, Count = count_all(palindrome(N,Mod,_X)), println(N=Count), fail, nl. go3 => true. palindrome(N,Mod,X) => X = new_list(N), X :: 0..9, Y :: 10**(N-1)..10**N-1, to_num(X,10,Y), % is a palindrome foreach(I in 1..N div 2) X[I] #= X[N-I+1] end, Y mod 11 #= Mod, solve(X). % % converts a number Num to/from a list of integer List given a base Base % to_num(List, Base, Num) => Len = length(List), Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).