/* Ani's PIN puzzle in Picat. From https://www.reddit.com/r/puzzles/comments/1e76okh/are_you_able_to_figure_out_what_anis_pin_is/ """ Ani is trying to use an ATM, but she's forgotten the PIN for her bank card. She randomly tries the following 6 _incorrect_ guesses: 5 7 2 6 7 3 5 8 1 1 9 1 7 6 2 8 4 8 8 2 9 3 0 7 She suddently remembers a property of here PIN - there are no repeated digits. However, she only has one more try at entering a correct PIN, or her card and account will be locked. She doesn't know, but it turns out that in each of her attempts, there was one correct digits entered in correct position. Knowing this information - Can you deduce Ani's PIN? """ Solution: [4,3,2,1] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go ?=> Guesses = [[5,7,2,6], [7,3,5,8], [1,1,9,1], [7,6,2,8], [4,8,8,2], [9,3,0,7] ], N = Guesses[1].len, X = new_list(N), X :: 1..9, all_different(X), foreach(Guess in Guesses) sum([X[I] #= Guess[I] : I in 1..N]) #= 1 end, solve(X), println(X), fail, nl. go => true.