/* Number puzzle in Picat. From Muhammad Zain Sarwar: "This Number Puzzle Will Blow Your Mind — Can You Solve It? - Cracking the 4-Digit Code" """ This puzzle revolves around Eliot who is trying to find a mysterious four-digit number by following the clues given by Drew. Eliot can find that number by carefully understand the meaning of each clues provided by Drew. The Puzzle Statement Eliot has given a four-digit number in which all digits are identical. The statement that Eliot finds insufficient at first but later helps him to find that mysterious number. The main clues provided by Drew are given below. - The number is the combination of four identical digits (e.g., 1111, 2222, etc.) - Eliot can only determine the number if the product of its digits is not unique. - The first digit of the square of this product must be odd. - The number cannot be 1111, 5555, 7777, 8888, or 9999. """ num = 6666 [d = 6,x = [6,6,6,6],prod = 1296,prodDigits = [1,2,9,6], prodDigitsProd = 108, prodSquare = 1679616,prodSquareDigits = [1,6,7,9,6,1,6]] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go ?=> N = 4, member(D,0..9), % - The number cannot be 1111, 5555, 7777, 8888, or 9999. not membchk(D,[1,5,7,8,9]), % The number is the combination of four identical digits (e.g., 1111, 2222, etc.) X = [D : _ in 1..N], % Eliot can only determine the number if the product of its digits is not unique. Prod = X.prod, % This part is not needed ProdDigits = Prod.to_string.map(to_int), ProdDigitsProd = ProdDigits.prod, % - The first digit of the square of this product must be odd. ProdSquare = Prod*Prod, ProdSquareDigits = ProdSquare.to_string.map(to_int), ProdSquareDigits[1] mod 2 == 1, println(num=X.map(to_string).join('')), println([d=D,x=X,prod=Prod,prodDigits=ProdDigits,prodDigitsProd=ProdDigitsProd,prodSquare=ProdSquare,prodSquareDigits=ProdSquareDigits]), fail, nl. go => true.