/* https://www.briddles.com/riddles/number-sequence #1 """ 6 14 36 98 276 ? """ data = [[[6,14,36],98], [[14,36,98],276]] unknown = [36,98,276] ops = (map)[infix = [+,-,*,/]] constants = [1,2] maxCount = 7 code = ((C + (2 * (C - 2))) - A) = [[[6,14,36],98],[[14,36,98],276]] = [[36,98,276] = 788] The intended solution: """ 794 The nth term in the series is given by the sum of x^n for x in the range 1 to 3, i.e. 1^n + 2^n + 3^n. Thus the first term is 1^1 + 2^1 + 3^1 = 1 + 2 + 3 = 6, the second term is 1^2 + 2^2 + 3^2 = 1 + 4 + 9 = 14, and so on. The sixth term is then 1^6 + 2^6 + 3^6 = 1 + 64 + 729 = 794. """ Using ** /2 blows up, but pow_mod2/2 works: [program = pow_mod2(3,A) + (1 + pow_mod2(2,A)),res = 794,count = 1] [program = pow_mod2(2,A) + 1 + pow_mod2(3,pow_mod2(A,1)),res = 794,count = 1] [program = pow_mod2(3,A) + 1 * (1 + pow_mod2(2,A)),res = 794,count = 1] [program = pow_mod2(3,A) - A + pow_mod2(2,A) + (A + 1),res = 794,count = 1] */ data(briddles_1,Data,Vars,Unknown,Ops,Constants,MaxSize,Params) :- Seq = [6,14,36,98,276], make_point_seq(Seq,Data,Unknown,Vars), % Using **/2 blows up, so we restrict to a smaller % space using pow_mod2/2. Ops = [+,-,*,/,pow_mod2], Constants = 1..6, % ++ [random(-10,10) : _ in 1..10], MaxSize = 21, Params = new_map().