/* 4x4 grid equations in Picat. https://puzzling.stackexchange.com/questions/102658/4x4-grid-equations?noredirect=1 """ Can you place all numbers from 1 to 16 into cells, such that the following 8 equations hold? Note that the operator "/" only works for non-remainder division, i.e. you can have "8 / 4" but not "8 / 3". As usual multiplication and division are performed before addition and subtraction. Good luck! A + B / C = D + - - + E / F + G = H * * / / I + J + K = L = = = = M - N / O = P """ This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> All = [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P], All :: 1..16, all_different(All), A + B / C #= D, E / F + G #= H, I + J + K #= L, M - N / O #= P, A + E * I #= M, B - F * J #= N, C - G / K #= O, D + H / L #= P, solve($[ff,split],All), printf("%2d + %2d / %2d = %d\n",A,B,C,D), println(" + - - +"), printf("%2d / %2d + %2d = %2d\n",E,F,G,H), println(" * * / /"), printf("%2d + %2d + %2d = %2d\n",I,J,K,L), println(" = = = ="), printf("%2d - %2d / %2d = %2d\n",M,N,O,P), nl, fail, nl. go => true.