/* Magic Square product in Picat. From Chris Smith: https://twitter.com/aap03102/status/1189978185032712198 """ ------------- | | | | 70 ------------- | | | | 32 ------------- | | | | 162 ------------- 72 120 42 Fill the space with the numbers 1,2,3,4,5,6,7,8,9 so that the product of the three numbers in a row or column matches the end of that row or column, """ There is one unique solution: 2 5 7 4 8 1 9 3 6 This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 3, RowProducts = [70,32,162], ColumnProducts = [72,120,42], X = new_array(N,N), Vars = X.vars, Vars :: 1..9, all_different(Vars), foreach(I in 1..N) prod([X[I,J] : J in 1..N]) #= RowProducts[I], prod([X[J,I] : J in 1..N]) #= ColumnProducts[I] end, solve(Vars), foreach(Row in X) println(Row) end, nl, fail, nl. go => true.