So, I am trying to write a program that figures out the correct combination to unlock something in a game. This question is going to need a bit of mathematical knowledge also.
Here are examples of randomly generated formulae that can be used:
Output 1 = (F - (((B + (D - E)) - C) * 1))
Output 2 = (((((((C - (((((F - E) - 5) - 1) + 9)^2))^2) * D) * 6)^2) * 7) - B)
The solution for this would be: C = 8, B = 5, E = 9, D = 5, F = 8 with output 1 being: 15 and output 2 being: 2109
The goal is to write the right combination of the variables B, C, D, E, F to get 15, and 2109 for output 1 and 2. >>You can only use integers 0 to 9 inclusive for B, C, D, E, F<<
You would only be given the goal for output 1 and 2, which is 15 and 2109, not the formula behind it.
My question is, is it possible to figure out an algorithm that can deconstruct a hidden formula such as this? Only one method needs to be figured out, the other formula can use the same method, then a massive list can be compared with solutions for both formulas, finding a match between them. I've messed around with incrementing B, C, D, E, F by 1 and trying to use math formulas for geometric sequences, which doesn't always end up giving the same common ratio therefore can't be a geometric sequence and can't be used... Figuring out the constant is easy, as setting all of B, C, D, E, F to 0 and then getting the result gives you the constant right away. Arithmetic sequences found by incrementing by 1 is also easy enough, but these formulas get complicated, so I'm genuinely wondering if it is mathmatically/computationally feasible to do this? If it matters, i'm trying to do it in python.
If you're dealing with arbitrary formulas like this see https://en.wikipedia.org/wiki/Diophantine_equation . The problem of finding integer solutions to Diophantine equations is NP-Complete. Essentially that means it's difficult to solve, but easy to verify the solutions, and you can in theory transform these problems into SAT problems.
I recommend using the z3 solver which has python bindings: https://github.com/Z3Prover/z3
Or you could use sympy: https://docs.sympy.org/latest/modules/solvers/diophantine.html