/* https://puzzles9.com/puzzles/number-sequence-puzzles-with-answers/ Puz254 """ 5 6 7 4 9 2 4 8 1 6 7 5 4 7 1 6 1 3 5 8 4 2 6 ? 6 Answer : 3 In the above puzzle, in each row , treat first two digits as one number and also last two digits as one number. subtract last number from first number to get middle number. 56 – 49 = 7 24 – 16 = 8 75 – 71 = 4 61 – 58 = 3 42 – 36 = 6 So, answer is 3. """ We rearrange to get the unknown last: 5 6 7 9 4 2 4 8 6 1 7 5 4 1 7 6 1 3 8 5 4 2 6 6 ? Nope, this is too hard to find. Adding to_num/2 does not help. */ /* data(puz254,Data,Vars,Unknown,Ops,Constants,MaxC) :- Matrix = [ [5,6,7,9,4], [2,4,8,6,1], [7,5,4,1,7], [6,1,3,8,5], [4,2,6,6,_] ], Ops = new_map([infix=["+","-"], user=["to_num"] ]), Constants = 1..1, MaxC = 7, ( nl, make_data_matrix(Matrix,Data,Unknown,Vars) % ; % nl, % make_data_matrix(Matrix.transp,Data,Unknown,Vars) ). */ /* A simpler variant. Let's simplify the problem a little and make the mid column the unknown instead: 5 6 4 9 7 2 4 1 6 8 7 5 7 1 4 6 1 5 8 3 4 2 3 6 ? For this simple version we find the solution: maxCount = 4 code = (B - to_num((C - A),D)) = [[[5,6,4,9],7],[[2,4,1,6],8],[[7,5,7,1],4],[[6,1,5,8],3]] = [[4,2,3,6] = 6] code = (to_num((A - C),B) - D) = [[[5,6,4,9],7],[[2,4,1,6],8],[[7,5,7,1],4],[[6,1,5,8],3]] = [[4,2,3,6] = 6] Without to_num/2, the following is also found: maxCount = 7 code = (B + ((10 * (A - C)) - D)) = [[[5,6,4,9],7],[[2,4,1,6],8],[[7,5,7,1],4],[[6,1,5,8],3]] = [[4,2,3,6] = 6] */ data(puz254,Data,Vars,Unknown,Ops,Constants,MaxC) :- Data = [ [[5,6,4,9],7], [[2,4,1,6],8], [[7,5,7,1],4], [[6,1,5,8],3] ], Unknown = [4,2,3,6], Vars = ["A","B","C","D"], Ops = new_map([infix=["+","-","*"] % , user=["to_num"] ]), Constants = [1,10], MaxC = 7.