/* An unusual number puzzle in Picat. Puzzle #34 from Clessa: "Math and logic puzzles for PC enthusiasts" """ Find a six-digit number which, when multiplied by an integer between 2 and 9 inclusive, gives the original six-digit number with its digits reversed. Thus, if the original number was 123,456, and the chosen integer is 8, then 123,456 x 8 should equal 654,321, which, of course, it doesn’t. However, it is possible to find more than one solution to this problem, but I’ll accept anyone that meets the required condition. """ There are two solutions: m = 9 numX = 109989 numY = 989901 m = 4 numX = 219978 numY = 879912 This 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 = 6, % decision variables X = new_list(N), X :: 0..9, Y = new_list(N), Y :: 0..9, M :: 2..9, % multiplier % constraints % Should be proper 6 digits numbers X[1] #!= 0, Y[1] #!= 0, Y = X.reverse(), to_num(X,10,NumX), NumY #= M * NumX, to_num(Y,10,NumY), Vars = X ++ Y ++ [M,NumX,NumY], solve($[ff,split],Vars), println(x=X), println(y=Y), println(m=M), println(numX=NumX), println(numY=NumY), nl, fail, nl. go => true. % % 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]).