/* Triangles https://puzzles9.com/puzzles/number-sequence-puzzles-with-answers/ """ All three triangles are interconnected. Find the answer by deriving a relation between them. 2 5 3 4 7 5 9 1 2 6 1 11 ? 5 9 Answer : 10 Difference of numbers in first two pentagons is in third pentagon at same location. difference of 2,5 = 3 4,5 = 1 7,9 = 2 6,11 = 5 1,10 = 9 So, answer is 10. """ * Here's the intended representation of the problem (representation 1) which give the expected solutution (? = 10): 2,3,5, 4,1,5 7,2,9 6,5,11 1,9,? maxCount = 1 code = (A + B) = [[[2,3],5],[[4,1],5],[[7,2],9],[[6,5],11]] = [[1,9] = 10] code = (B + A) = [[[2,3],5],[[4,1],5],[[7,2],9],[[6,5],11]] = [[1,9] = 10] * Another representation (which is not the indended one), below called representation 2 finds some alternatives solutions. A B C D E E is the unknown. The program finds a lot of different solutions: maxCount = 5 code = ((1 + (A * A)) - B) = [[[2,4,7,6],1],[[3,1,2,5],9]] = [[5,5,9,11] = 21] maxCount = 6 maxCount = 7 code = (((D + (A * A)) - C) - A) = [[[2,4,7,6],1],[[3,1,2,5],9]] = [[5,5,9,11] = 22] code = (B + ((A * (D - C)) - 1)) = [[[2,4,7,6],1],[[3,1,2,5],9]] = [[5,5,9,11] = 14] code = (((A * (A + B)) - C) - B) = [[[2,4,7,6],1],[[3,1,2,5],9]] = [[5,5,9,11] = 36] code = (C + (1 + (C * (D - C)))) = [[[2,4,7,6],1],[[3,1,2,5],9]] = [[5,5,9,11] = 28] code = (1 + (B * ((A * A) - B))) = [[[2,4,7,6],1],[[3,1,2,5],9]] = [[5,5,9,11] = 101] Adding "**" as operator give some other solutions: code = ((C - D) ** C) = [[[2,4,7,6],1],[[3,1,2,5],9]] = [[5,5,9,11] = -512] */ data(triangles,Data,Vars,Unknown,Ops,Constants,MaxC) :- Matrix = [[2,4,7,6,1], [3,1,2,5,9], [5,5,9,11,_] ], member(Representation,1..2), Ops = new_map([infix=["+","-","*"] ]), Constants = 1..1, if Representation == 1 then nl, make_data_matrix(Matrix.transp,Data,Unknown,Vars), % Data = [ % [[2,3],5], % [[4,1],5], % [[7,2],9], % [[6,5],11] % ], % Unknown = [1,9], % Vars = ["A","B"], MaxC = 2 else nl, make_data_matrix(Matrix,Data,Unknown,Vars), % Only show solutions with different values for % the unknown get_global_map().put("only_first_solution",true), % Data = [ % [[2,4,7,6],1], % [[3,1,2,5],9] % ], % Unknown = [5,5,9,11], % Vars = ["A","B","C","D"], MaxC = 8 end.