The train game is a game you play with the id number of a train/bus. For example:
(Credit to this website for the photo!)
Using those 4 numbers and the operators + - *
and /
to create the number 10
.
For example, using 1234
:
1 + 2 + 3 + 4 = 10
(2 * 3) + (4 * 1) = 6 + 4 = 10
And there may be many more solutions.
You must use each number at most once and at least once!
This project finds all the solutions to a particular train game problem :)
The assumptions it makes are:
- Only clean division occurs (i.e. if we have
a/b
, then this division is accepted iffa mod b = 0
) - No division by zero
- There are only 4 numbers as input (unless I make this better...)
Make sure you have stack at least version 1.9
. Older versions may work too!
To build the project:
stack build
To run the project:
stack exec train-game-exe -- *Intert 4 numbers here*
- Some solutions are 'identical', but get printed twice because the operation order is different. For example, solving
3577
gives us:- 5 * (3 - (7 / 7))
- (3 - (7 / 7)) * 5
- Having two of the same number means solutions are equivalent, but treated as two seperate solutions