Mornington Crescent
Every instruction is a trip on the London Underground. Stations are memory cells, and the program must end at Mornington Crescent.
Timwi, 2013 · Turing complete: yes · ●●○ moderate · esolangs.org
The idea
Mornington Crescent is a running joke from the BBC radio panel show I'm Sorry I Haven't a Clue. Players take turns naming London Underground stations, pretending to follow elaborate strategic rules, until someone "wins" by saying Mornington Crescent. The joke is that the rules do not exist.
Read the story
In 2013 the esolangs.org user Timwi turned the joke into a real language, with real rules. A program is a list of journeys: Take Northern Line to Euston. Each journey must be possible on the real Tube map. Execution starts at Mornington Crescent, and a valid program must end there.
It is camouflage of a sort, since a program reads like a set of travel directions. But mostly it is a punchline that happens to be Turing complete.
The machine
- Every station holds a value: a string or an arbitrary-size integer. At the start, each holds its own name: Waterloo holds
"Waterloo". - There is one accumulator, which starts as the whole of the input.
- An instruction
Take <Line> Line to <Station>is legal only if that line connects the current station to the destination. Then the pointer moves there and the accumulator swaps with the station's value.
Some stations do something else instead of swapping:
| Station | Does |
|---|---|
| Upminster | Add (if both are integers) |
| Chalfont & Latimer | Multiply |
| Cannon Street, Preston Road | Divide, remainder |
| Seven Sisters | Set the accumulator to 7 |
| Charing Cross | Character ↔ code point |
| Parsons Green | Parse the first integer out of a string |
| Paddington | Concatenate strings |
| Turnpike Lane | Reverse a string |
| Bank / Hammersmith | Storing at Bank also copies the value to Hammersmith, which keeps it |
| Temple, Angel, Marble Arch | Push a return point; jump back if the accumulator is non-zero; pop |
| Mornington Crescent | Print the accumulator and stop |
So you get numbers by visiting Seven Sisters, and loops by going to Temple and later to Angel. An illegal journey (a line that does not stop there) is a runtime error.
Example
A program that prints a word without ever writing it down:
A program that prints a word without ever writing it down:
Take Northern Line to Euston
Take Northern Line to Mornington Crescent
Traced by hand: both stations are on the Northern line. Arriving at Euston swaps the accumulator (the input) with Euston's value, so the accumulator now holds "Euston". Arriving at Mornington Crescent prints it. Output: Euston. The input is left behind at Euston.
For scale, the shortest Hello World listed on esolangs.org, by Martin Ender, is 110 journeys. Most of them shuttle values between Upminster, Hammersmith and Paddington to build character codes and glue strings.
Patterns it teaches
- Camouflage: code that looks like travel directions. It only fools someone who has never seen a program.
- Turing completeness: shown by translating a register machine. Stations are registers, and the Tube network is connected enough that any station can be reached.
Try this
- Trace what this prints: Euston (Northern), Seven Sisters (Victoria), Euston (Victoria), Mornington Crescent (Northern). Why is it not
7? - Now write a program that does print
7. Every ordinary station you pass through swaps, so plan where the 7 waits. - Hard: add two numbers read from input, using Parsons Green and Upminster.
Further
- esolangs.org/wiki/Mornington_Crescent
- Timwi's Esoteric IDE, an interpreter and debugger that supports it: github.com/Timwi/EsotericIDE
- The game: Mornington Crescent (game) on Wikipedia
See also
Non-interactive IO
Source esolangs.org (CC0) · Edit on esolangs.org