esolang

Hair

Code that looks like a hair style, on a tape where the pointer never knows how far it will move.

A(), 2025 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hello, World!

The idea

A() made Hair in 2025, so that code would look like a hair style. A program is mostly slashes and brackets. Memory is a tape of whole numbers without ends and one accumulator beside it.

Read the story

Two kinds of command leave things to chance. ( and ) move the pointer by a random amount of at least one cell, and [ jumps to a random ]. A program can still be sure of what it does. Moving only forward always lands on a cell that is still 0, and a loop with one ] after it has only one place to jump.

The machine

CommandDoes
( )Move forward or back a random number of cells
/ \Add 1 to the cell, take 1
{ }Add 1 to the accumulator, take 1
l -Cell becomes the accumulator; accumulator becomes the cell
[If the cell is not the accumulator, jump past a random ] after it
]Jump back to its own [
= ~Print the cell as a character; read one into it

A move is 1 to 10 cells, and the random numbers come from a fixed seed, so a run replays.

Example

Hello, World! Each line moves to a fresh cell and counts up to one character, 72 slashes for the H.

Hello, World! Each line moves to a fresh cell and counts up to one character, 72 slashes for the H.

The truth machine. 49 { make the accumulator 49, a 1. On a 1 the cell equals the accumulator, so the loop prints 1 for ever. On a 0 the [ jumps past the only ] and the last = prints 0 once.

Expected: 0

The specification also has a cat that never stops and a program that prints random bits until a jump happens to land past the last ].

Patterns it teaches

  • Nondeterminism: random moves and random jumps, and programs written so that the chance does not matter.

Further

Accumulator-based

Cell-based

Write your own in Run Convert a program from Hair

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: hair.

Command line

shib run hair -e '~{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[=]=' --input '0'
shib manual hair

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/hair.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org