/* From Muhammad Zain Sarwar: "Only People with 130+ IQ Can Solve This Missing Number Puzzle — Can You?" https://medium.com/puzzle-sphere/only-people-with-130-iq-can-solve-this-missing-number-puzzle-can-you-705aaff172aa """ [ 10 4 9 7 ? 8 3 6 10 8 6 ? 5 8 4 2 12 ? 7 1 5 3 5 3 Represented as H A G B F C E D ] Circle 1 4 6 8 1 7 5 3 10 [diagonal pairs: 4-7, 6-5, 8-3, 1-10] Circle 2 7 8 2 3 5 4 10 9 [diagonal pairs: 7-5, 8-4, 2-10, 3-9] Circle 3 8 ? ? 3 5 12 6 ? [diagonal pairs: 8-5, B-12, C-6, 3-H] Your task is to find the missing number in the third circle. """ Is symbolic regression able to find the solution? Answer: Not what I can see. But see test/0 and test2/0 for for other approaches. The solution is to check the diagonal pairs in the circles: A-E, B-F, C-G, D-H However, I don't want to give the program too much help. Here are some suggested solutions from the program: AllGood: [program = B + (E + F - D - E),res = 9,count = 1] resultMap = [9 = 1] AllGood: [program = B - D + F,res = 9,count = 9] [program = 1 * A + E + 1 * (1 - (1 + D)),res = 10,count = 8] [program = A + (1 - (B - (1 + F * 1) - F)),res = 34,count = 8] [program = C - (D - G) * 1,res = 3,count = 5] [program = G + (C - D),res = 3,count = 4] [program = A - 1 * D + E,res = 10,count = 1] [program = 1 * F + (B - D),res = 9,count = 1] [resultMap = [10 = 2,9 = 2,3 = 2,34 = 1] The objective in this symbolic regression model to recover H, but this is really not related to the other values. We see above that we get some different solutions: 9, 10,3,and 34. So I consider this a fail for my symbolic regression representation. Perhaps there are some other representations that not use too much hints? That being said, once one realize that it has something to do with the diagonal pairs, logic program or constraint modeling solves the problem in a flash. */ import cp. % for test2/0. data(missing_number2,Data,Vars,Unknown,Ops,Constants,MaxSize,Params) :- Data = [ [[4,6,8,1,7,5,3],10], [[7,8,2,3,5,4,10],9] ], Ops = [+,-,*], Constants = 1..1, Vars = ['A','B','C','D','E','F','G'], Unknown = [8,0,0,3,5,12,6], % 0 is a dummy number MaxSize = 21, Params = new_map([ init_size=1000, num_gens=10, show_only_good=false ]). /* Hmm, but there's a much simpler way to solve the problem; no need to waste a lot of CPUs to solve it with symbolic regression. unknown = [8,1,7,3,5,12,6,10] = [b = 1,c = 7,h = 10] = 13 */ test => member(B,1..10), member(C,1..10), member(H,1..10), % The diagonal pairs 8+5 = Total, B+12 = Total, C+6 = Total, 3+H = Total, Unknown = [8,B,C,3,5,12,6,H], println(unknown=Unknown=[b=B,c=C,h=H]=Total), fail. /* Or use constraint modeling: unknown = [8,1,7,3,5,12,6,10] = [b = 1,c = 7,h = 10] = 13 */ test2 => B :: 1..10, C :: 1..10, H :: 1..10, 8 + 5 #= Total, B + 12 #= Total, C + 6 #= Total, 3 + H #= Total, Unknown = [8,B,C,3,5,12,6,H], solve(Unknown), println(unknown=Unknown=[b=B,c=C,h=H]=Total), fail.