/MathExpress

A simple mathematical expressions maker and solver

Primary LanguagePython

MathExpress

Why?

Yesterday I have seen on the internet a simple mathematical exercise:

Write an expression which respects the following requirements:

  • Must appear only sum, subtraction and multiplication
  • Must appear numbers 2, 4, 5, 10, 12 only once
  • Result must be 22

Initially I have tried to resolve it by hand with a "trial and error" approach, then I have decided to write a simple and dumb python script. It consists of two parts: the first one generates all the possible expressions which respect the first 2 requirements, the second one solves the generated expressions to check if they also respect the third requirement.