Search code examples
javatreegenetic-algorithmpostfix-notation

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


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.


Solution

  • 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.