Half-Broken Car in Heavy Traffic
You are a car on a chaotic highway. Every road sign you obey also changes your memory, and you cannot turn left.
Niels Serup, 2011 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Niels Serup made HBCHT in 2011. The program is a map with one car o and one exit #. Signs > < ^ v point the car somewhere and, at the same time, act on memory like brainfuck: right moves to the next cell, left to the previous, up adds one, down takes one away.
Read the story
The car is half broken. It can go straight, turn right or reverse, but a sign that would turn it left is ignored, memory effect and all. Worse, nobody knows which way the car faces at the start. A program has to work for all four directions, so most of it is a funnel that catches the car and points it the same way.
The machine
| Sign | Does |
|---|---|
> | Turn right (on the map), next cell |
< | Turn left, previous cell |
^ | Turn up, add one |
v | Turn down, take one |
/ | Turn clockwise if this cell equals the one before it |
# | The exit |
The map wraps at its edges. Input fills cells 0, 1 and on; at the exit the car returns every cell that was written. @intext and @outtext lines make input and output text instead of numbers.
Example
The increment program.
The increment program. Whatever way the car starts, the funnels bring it to the exit with one more in cell 0. With text in and out, a becomes b.
With numbers, only cell 0 changes.
Patterns it teaches
- Two-dimensional control flow: every move is also a write, so routes have to be planned for their side effects.
- Nondeterminism: a random start direction that the program has to absorb.
- Turing completeness: bf2hbcht turns brainfuck without I/O into it.
Further
- esolangs.org/wiki/Half-Broken_Car_in_Heavy_Traffic
- hbcht, the Python interpreter and compiler
See also
Two-dimensional languages
Cell-based
Write your own in Run Convert a program from Half-Broken Car in Heavy Traffic
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: hbcht.
Command line
shib run hbcht -e '@intext
@outtext
; Decrement the first memory cell once without changing the other cells.
v v
v < <>
^
^ >>^<
>v<o>^<
v
v v
> v<
#
> ^<
^ ' --input 'b'shib manual hbchtSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/hbcht.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org