/* https://puzzles9.com/puzzles/number-sequence-puzzles-with-answers/2/ Puz241 """ 4 1 10 4 22 10 46 22 3 8 18 ?? """ Encoded as A B C * Representation 1 data = [[[4,1],3], [[10,4],8], [[22,10],18]] unknown = [46,22] maxCount = 5 code = (A + ((B - A) / 3)) = [[[4,1],3],[[10,4],8],[[22,10],18]] = [[46,22] = 38.0] code = (B + ((A + 2) / 3)) = [[[4,1],3],[[10,4],8],[[22,10],18]] = [[46,22] = 38.0] code = ((A + (B + A)) / 3) = [[[4,1],3],[[10,4],8],[[22,10],18]] = [[46,22] = 38.0] code = (((A * 5) - 2) / 6) = [[[4,1],3],[[10,4],8],[[22,10],18]] = [[46,22] = 38.0] (4 + (1-4) / 3) = 3 (10 + (4-10) / 3) = 8 (22 + (10-22) / 3) = 18 (46 + (22-46) / 3) = 38 * Representation 2 data = [[[4,10,22],46],[[1,4,10],22]] unknown = [3,8,18] code = (C + (C + 2)) = [[[4,10,22],46],[[1,4,10],22]] = [[3,8,18] = 38] code = (6 + (B * 4)) = [[[4,10,22],46],[[1,4,10],22]] = [[3,8,18] = 38] code = (A + (7 * (2 + A))) = [[[4,10,22],46],[[1,4,10],22]] = [[3,8,18] = 38] ... But we want to use all three variables ("use_all_variables_remove_dups"): code = (B + (2 * (C - A))) = [[[4,10,22],46],[[1,4,10],22]] = [[3,8,18] = 38] code = (C + (4 * (B - A))) = [[[4,10,22],46],[[1,4,10],22]] = [[3,8,18] = 38] The intended solution: """ Answer : 38 In the above puzzle, add 2 to the twice of left number in the top row to get the next number in the same location of next box. similarly do for remaining numbers,. 4*2 + 2 = 10*2 + 2 = 22*2 + 2 = 46 ; 1*2 + 2 = 4*2 + 2 = 10*2 + 2 = 22 ; 3*2 + 2 = 8*2 + 2 = 18*2 + 2 = 38 ; So, answer is 38. """ */ data(puz241,Data,Vars,Unknown,Ops,Constants,MaxC) :- Matrix = [[ 4, 1, 3], [10, 4, 8], [22,10,18], [46,22, _] ], Ops = new_map([infix=["+","-","*","/"] % , user=["to_num"] ]), 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) ).