/* Four got it (New Scientist puzzle #3391) in Picat. https://enigmaticcode.wordpress.com/2022/06/18/puzzle-172-four-got-it """ From New Scientist #3391, 18th June 2022 Emma Neesha is a forgetful sort, and she has just locked herself out of her house with her keys still inside. Not to worry, she installed keypads on both her house and car for such occasions. Unfortunately, she has also forgotten the four-digit code to her house. This shouldn’t be a problem, because she keeps a code clue in her wallet. It says: “Four times the car’s four-digit code”. Well, that is fine, but she has forgotten that one too. Fortunately, Emma is prepared: she has a clue written down for the car’s code as well. Pulling that one out, it reads: “The reverse of the house code”. Oh dear. Can you help? """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => [A,B,C,D]::0..9, (1000*A+100*B+10*C+D)*4 #= (1000*D+100*C+10*B+A), solve([A,B,C,D]), println([A,B,C,D]), fail, nl. % % Are there any solutions with other multiplies than 4? % Yes. For M = 9 there is another solution. % [1,0,8,9] % go2 => member(M,2..9), [A,B,C,D]::0..9, (1000*A+100*B+10*C+D)*M #= (1000*D+100*C+10*B+A), % disallow 0 solutions A #> 0, solve([M,A,B,C,D]), println(M=[A,B,C,D]), fail, nl. % % And add a multiplier for RHS as well. % Require that M > N (symmetry breaking) and skipping N=1 % % [m = 3,n = 2 = [4,3,5,6]] % [m = 6,n = 4 = [4,3,5,6]] % [m = 6,n = 5 = [4,5,4,5]] % [m = 6,n = 5 = [4,9,9,5]] % [m = 7,n = 3 = [3,2,6,7]] % [m = 7,n = 4 = [1,2,1,2]] % [m = 7,n = 4 = [1,3,3,2]] % [m = 7,n = 4 = [1,4,5,2]] % [m = 7,n = 4 = [1,5,7,2]] % [m = 7,n = 4 = [1,6,9,2]] % [m = 7,n = 4 = [2,3,0,4]] % [m = 7,n = 4 = [2,4,2,4]] % [m = 7,n = 4 = [2,5,4,4]] % [m = 7,n = 4 = [2,6,6,4]] % [m = 7,n = 4 = [2,7,8,4]] % [m = 7,n = 4 = [3,5,1,6]] % [m = 7,n = 4 = [3,6,3,6]] % [m = 7,n = 4 = [3,7,5,6]] % [m = 7,n = 4 = [3,8,7,6]] % [m = 7,n = 4 = [3,9,9,6]] % [m = 7,n = 4 = [4,6,0,8]] % [m = 7,n = 4 = [4,7,2,8]] % [m = 7,n = 4 = [4,8,4,8]] % [m = 7,n = 4 = [4,9,6,8]] % [m = 8,n = 2 = [2,1,7,8]] % [m = 8,n = 3 = [2,7,2,7]] % [m = 8,n = 3 = [2,9,9,7]] % [m = 9,n = 2 = [1,8,1,8]] % [m = 9,n = 2 = [1,9,9,8]] % [m = 9,n = 6 = [4,3,5,6]] % go3 => member(M,2..9), member(N,2..M-1), [A,B,C,D]::0..9, (1000*A+100*B+10*C+D)*M #= (1000*D+100*C+10*B+A)*N, % disallow 0 solutions A #> 0, solve([M,N,A,B,C,D]), println([m=M,n=N=[A,B,C,D]]), fail, nl.