Create a simple console game in which the computer generates a random math expression like 7 * 9 / 3
and asks the user to solve the equation.
The game must take a level parameter, the level determines the length of the generated equation; for example:
--level 1
68 = 68
17 = 17
40 = 40
97 = 97
58 = 58
--level 2
75 + 12 = 87
62 + 15 = 77
88 + 2 = 90
93 + 22 = 115
90 * 11 = 990
--level 3
( 21 + 13 ) * 56 = 1904
82 - 19 + 16 = 79
51 * ( 68 - 2 ) = 3366
41 + 55 + 31 = 127
82 * 22 - 16 = 1788
--level 4
99 * 1 * ( 1 + 79 ) = 7920
( 80 + 84 ) * ( 89 + 65 ) = 25256
54 * 64 * 75 * 68 = 17625600
89 + 10 - 8 * 2 = 83
12 + 70 + 48 + 39 = 169
Please note that level 1 is useless! It is here for completeness.
The game should start with a command like ./game --level 3
The numbers in the equations must be integers between and including 1 to 100.
The game must produce equations with addition +
or multiplication *
operators like ( 21 + 13 ) * 56
.
The game should print out the simplest form of the expressions (by removing unnecessary parentheses), for example it should simplify (5 + 3) + (8 * 3)
to 5 + 3 + 8 * 3
.
Add subtraction -
operator.
How many different equations can be generated at any level?
For example, at level 1, 100 different equations can be generated.
You can use any of the following languages: Java, Scala, Haskell, Swift, C#, F# or JavaScript.