Skip to content
Play the train game in Haskell!
Haskell Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
src
test
.gitignore
ChangeLog.md
LICENSE
README.md
Setup.hs
getExecutable.sh
package.yaml
stack.yaml

README.md

The Train Game in Haskell!

What's the train game?

The train game is a game you play with the id number of a train/bus. For example:

Train Carriage Number

(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!

What does this project do?

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 iff a mod b = 0)
  • No division by zero
  • There are only 4 numbers as input (unless I make this better...)

How do I run it?

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*

Current issues

  • 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
You can’t perform that action at this time.