/* Pyramid missing number puzzle in Picat. From Muhammad Zain Sarwar: "People With an IQ of 140+ Can Find These Missing Numbers in This Pyramid!" """ ? ? 56 19 ? 28 7 ? ?_ ? _ ? ? 7 ? ? """ [103] [47,56] [19,28,28] [7,12,16,12] [2,5,7,9,3] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import sat. main => go. go ?=> X = [ [_], [_,56], [19,_,28], [7,_,_,_], [_,_,7,_,_]], X :: 1..200, Ls = [ [[1,1],[2,1],[2,2]], [[2,1],[3,1],[3,2]], [[2,2],[3,2],[3,3]], [[3,1],[4,1],[4,2]], [[3,2],[4,2],[4,3]], [[3,3],[4,3],[4,4]], [[4,1],[5,1],[5,2]], [[4,2],[5,2],[5,3]], [[4,3],[5,3],[5,4]], [[4,4],[5,4],[5,5]] ], foreach(L in Ls) X1 = X[L[1,1],L[1,2]], X2 = X[L[2,1],L[2,2]], X3 = X[L[3,1],L[3,2]], X1 #= X2 + X3 end, solve(X), println(X), foreach(Row in X) println(Row) end, nl, fail, nl. go => true. /* Are there some other solutions? Well, these are not very interesting... [[104],[47,56],[19,27,28],[7,11,15,12],[3,3,7,7,4]] [a = 1,b = 1,c = 1] [104] [47,56] [19,27,28] [7,11,15,12] [3,3,7,7,4] [[103],[47,56],[19,28,28],[7,12,16,12],[2,5,7,9,3]] [a = 1,b = 1,c = 0] [103] [47,56] [19,28,28] [7,12,16,12] [2,5,7,9,3] [[105],[47,56],[19,26,28],[7,10,14,12],[4,1,7,5,5]] [a = 1,b = 1,c = 2] [105] [47,56] [19,26,28] [7,10,14,12] [4,1,7,5,5] [[102],[47,56],[19,29,28],[7,13,17,12],[1,7,7,11,2]] [a = 1,b = 1,c = -1] [102] [47,56] [19,29,28] [7,13,17,12] [1,7,7,11,2] */ go2 ?=> nolog, X = [ [_], [_,56], [19,_,28], [7,_,_,_], [_,_,7,_,_]], X :: 1..10000, [A,B,C] :: -10..10, Ls = [ [[1,1],[2,1],[2,2]], [[2,1],[3,1],[3,2]], [[2,2],[3,2],[3,3]], [[3,1],[4,1],[4,2]], [[3,2],[4,2],[4,3]], [[3,3],[4,3],[4,4]], [[4,1],[5,1],[5,2]], [[4,2],[5,2],[5,3]], [[4,3],[5,3],[5,4]], [[4,4],[5,4],[5,5]] ], foreach(L in Ls) X1 = X[L[1,1],L[1,2]], X2 = X[L[2,1],L[2,2]], X3 = X[L[3,1],L[3,2]], X1 #= A* X2 + B* X3 + C end, Vars = X ++ [A,B,C], solve(Vars), println(X), println([a=A,b=B,c=C]), foreach(Row in X) println(Row) end, nl, fail, nl. go2 => true.