esolang

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

Expected: b

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

SignDoes
>Turn right (on the map), next cell
<Turn left, previous cell
^Turn up, add one
vTurn 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.

Expected: 6 7

Patterns it teaches

Further

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 hbcht

Source

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