/* Tantalizer 487: Number system in Picat. https://enigmaticcode.wordpress.com/2017/03/22/tantalizer-487-number-system/ """ From New Scientist #1038, 10th February 1977 [link] If you look up the phone number of Sir William Watergate in the book, you will not find it. He is ex-directory. But you can work it out from the list of ten numbers below. Each of the ten has exactly one of Sir William's digits correctly placed. Consider the first number, 14073, for instance. It implies that Sir William is not on 14257, which would mean two digits correctly placed, nor on 40731, which would mean none. 14073 29402 35862 42936 50811 63136 79588 84771 98174 07145 If I just add that Sir William's true number has five digits, can you discover it? """ 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 => N = 10, S = 5, D = [ [1,4,0,7,3], [2,9,4,0,2], [3,5,8,6,2], [4,2,9,3,6], [5,0,8,1,1], [6,3,1,3,6], [7,9,5,8,8], [8,4,7,7,1], [9,8,1,7,4], [0,7,1,4,5]], X = new_list(S), X :: 0..9, foreach(I in 1..N) sum([X[J] #= D[I,J] : J in 1..S]) #= 1 end, solve(X), println(X), fail, nl.