Turing Trains | Isometric | Wang Tiles | Maze Arrays | i Logo HOME

# Turing Trains

 computational train track layouts menu

## Triangular Numbers

The triangular number of n is calculated by adding up all the numbers below (and including) n. So if n=5 then the triangular number = 5+4+3+2+1 = 15.

The concept dates back to the 5th century BC. Each term is given by the formulae n(n+1)/2.

More information on the Triangular Numbers can be found at Wikipedia.

 n num 0 1 2 3 4 5 6 7 0 1 3 6 10 15 21 28

Two functions are used:

1. Count down function to decrement n.
2. Adder function, to add successive terms into S.

### Operation

Clear register S. Enter binary value of n and start the train from the station. When the train returns and halts, the nth triangular number can be read from the output register S.

 Click layout to pause/run train Click points to switch 0/1 Click start circle to reset train/points
 Lazy points switch between upper 0 or lower 1 branch lines Trains arriving on a branch line switch the point to that line Sprung points allow branch line trains to join the main line All main line trains go straight ahead and never 'branch off'

Notes

1. If the nth term exceeds 31, register S overflows and the train returns to the lower station platform as an error. This should not happen as the maximum value for n=7 is 28. Possibly register S was not cleared before calculation began.
2. To obtain the correct result, the value of n is added to register S first. This creates an extra 'add 0' calculation at the end.
3. The original value of n is 'lost' as the register counts down.

See alternative version of triangular number using a comparator.

 cr31.co.uk
 zoom in to enlarge layouts