/* https://puzzles9.com/puzzles/number-sequence-puzzles-with-answers/2/ Puz240 """ 3 5 ?? 24 30 42 5 3 4 2 1 2 """ Intended solution: """ Answer : 14 In the above puzzle, add the bottom two numbers and multiply it with top number to get middle number in each triangle. (5+3) * 3 = 24 ; (4+2) * 5 = 30 ; (1+2) * 14 = 42 ; So, answer is 14. """ Encoded as D A B C * Representation 1 data = [[[24,5,3],3], [[30,4,2],5]] unknown = [42,1,2] maxCount = 3 code = (A / (B + C)) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 14.0] 3 * 5+3 = 24 5 * 4+2 = 30 14 * 1+2 = 42 Some alternatives not using all variables: [program = 9 - C - C,res = 5,count = 25] [program = A / (C + B),res = 14.0,count = 20] [program = 10 - 2 * B + 3,res = 11,count = 18] [program = 8 - (B + (C - 3)),res = 8,count = 11] [program = 9 - C - (B - 5 + 3),res = 8,count = 3] [program = 9 - C - (B - 2),res = 8,count = 1] resultMap = [8 = 3,14.0 = 1,11 = 1,5 = 1] * Representation 2 (transposed data matrx) data = [[[24,30],42], [[5,4],1], [[3,2],2]] unknown = [3,5] No solution found using this representation. */ data(puz240,Data,Vars,Unknown,Ops,Constants,MaxSize,Params) :- Matrix = [[24, 5, 3, 3], [30, 4, 2, 5], [42, 1, 2, _] ], Ops = [+,-,*,/], Constants = 1..20, MaxSize = 5, make_data_matrix(Matrix,Data,Unknown,Vars), % make_data_matrix(Matrix.transp,Data,Unknown,Vars), % no solution Params = new_map([num_gens=30]).