/* https://puzzles9.com/puzzles/number-sequence-puzzles-with-answers/2/ Puz240 """ 3 5 ?? 24 30 42 5 3 4 2 1 2 """ 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: code = ((9 - C) - C) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 5] code = ((A / 3) - 5) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 9.0] code = (9 - (C + C)) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 5] code = (9 - (C * 2)) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 5] code = (A / (C + (C + 2))) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 7.0] code = (B + (7 - (C * 3))) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 2] code = (((3 + 10) - B) - B) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 11] code = (((1 + 10) - C) - B) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 8] code = ((10 + (4 - B)) / C) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 6.5] code = (1 + (4 / (B - 3))) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = -1.0] code = ((A / (B + 1)) - 1) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 20.0] code = ((A / (C + 3)) - 1) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 7.4] code = ((10 * (4 / B)) - 5) = [[[24,5,3],3],[[30,4,2],5]] = [[42,1,2] = 35.0] * Representation 2 data = [[[24,30],42], [[5,4],1], [[3,2],2]] unknown = [3,5] No solution found using this representation. 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. """ */ data(puz240,Data,Vars,Unknown,Ops,Constants,MaxC) :- Matrix = [[24, 5, 3, 3], [30, 4, 2, 5], [42, 1, 2, _] ], Ops = new_map([infix=["+","-","*","/"] ]), Constants = 1..10, MaxC = 5, get_global_map().put("use_all_variables_remove_dups",true), ( nl, make_data_matrix(Matrix,Data,Unknown,Vars) % ; % nl, % make_data_matrix(Matrix.transp,Data,Unknown,Vars) ).