Need program to automatically find number X using basic mathematical operations and 6 random numbers

63 views Asked by At

I have some number X (0-999) and six random numbers (<50).

I need program to automatically finds number X (or number closest to X if its not possible to find X) using basic mathematical operations with brackets and those 6 random numbers.

Can someone recommend me a way to approach this problem? I read somewhere that I should use postfix-notations and genetic algorithms but I don't know much about either of those.

2

There are 2 answers

0
user3386109 On BEST ANSWER

Postfix notation avoids the complications that come with using brackets. It allows you to model the equation as

  1. every permutation of the six numbers (6! = 720 permutations in all), followed by
  2. every combination of five operators, where each operator is one of four choices (4^5 = 1024 combinations in all)

The total number of possible equations is 720*1024 = 737280. So I see no reason to use a genetic algorithm, you can simply try all the possibilities. After finding the best postfix solution, you'll need to convert to infix with the appropriate brackets.

0
fejfo On

If you are asking about a random equation you need to solve your program can solve it just like you would. example: (10x + 5x + 8)*8 = (x+2)^2 + 3 step 1 work out brackets: 80x + 40x + 64 = x² + 4x + 4 + 3 step 2 move everything to the left: 80x + 40x + 64 - x² - 4x + 4 +3 step 3 simplify: -x² + 116x + 71 step 4 use the formula