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 . |
|
Two functions are used:
- Count down function to decrement n .
- 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 n th 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
- If the n th 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.
- 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.
- The original value of n is 'lost' as the register counts down.
See alternative version of triangular number using a comparator.