/* Homework baffles dad problem in Picat. From MindYourDecisions: """ A dad was baffled by this homework question for his daughter, [https://www.reddit.com/r/daddit/comments/10eua2h/so_yeah_my_daughter_said_she_needed_help_with_her/ ] and many other adults were stumped by it too. Mr. Ruis gives his class clues about a 6-digit mystery number. * The 3 is in a place that is 10 times greater than the place of 0. * The 1 is in a place that is 10 times less than the place of 0. * The 4 is in a place that is 10 times more than the place of the 3. * The 9 is in a place that is 100 times less than the 1. * The 2 is in a place that is 10 times more than the 9. """ Solution: x = [9,2,1,0,3,4] = 921034 l = [4,3,2,5,6,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 ?=> N = 6, Digits = [0,1,2,3,4,9], X = new_list(N), X :: 0..9, % all_different(X), % not needed element(X0,X,0), element(X1,X,1), element(X2,X,2), element(X3,X,3), element(X4,X,4), element(X9,X,9), % The 3 is in a place that is 10 times greater than the place of 0. X3 #= X0-1, % The 1 is in a place that is 10 times less than the place of 0. X1 #= X0+1, % The 4 is in a place that is 10 times more than the place of the 3. X4 #= X3-1, % The 9 is in a place that is 100 times less than the 1. X9 #= X1+2, % The 2 is in a place that is 10 times more than the 9. X2 #= X9-1, L = [X0,X1,X2,X3,X4,X9], Vars = X ++ L, solve(Vars), println(x=X=X.map(to_string).join('')), println(l=L), nl, fail, nl. go => true.