esolang

Two Four

Four instructions, each written as two bits, on a field of sixteen bits.

00Her0, 2022 · Turing complete: no · ●○○ easy · esolangs.org

Tested with 9 known programs · Test method

Run it

Expected: 1110 0000 0000 0000 ***

The idea

00Her0 made Two Four in 2022 and named it for its four instructions, each written as two bits. They work on a field of 16 bits, often drawn as a 4 by 4 square, with one pointer called the soba, the Selected One Bit Accumulator.

Read the story

Each line of the program is a tape. The program runs once from top to bottom and then shows the field. There are no loops, so every program stops, and 16 bits are all the memory there is. The specification says it is almost certainly not Turing complete.

The machine

InstructionDoes
00If the bit at the soba is 0, move 4 on; if 1, move 1 on
11Flip the bit at the soba; every second 11 in a row also moves 1 on
10Move the soba back to 0
01If the bit at the soba is 0, skip the rest of this line

The soba wraps from 15 back to 0. The input fills the field from bit 0, as the specification's input layer does. The output is the field as the specification's interpreter prints it, four bits a row and then ***.

Example

The AND reads bits 0 and 1 and writes bit 2.

The AND reads bits 0 and 1 and writes bit 2. On 11 the first 00 moves to bit 1, the 01 passes, the second 00 moves to bit 2 and 11 sets it.

Expected: 1000 0000 0000 0000 ***

The OR takes two lines. The first sets bit 2 only when both inputs are 0, and the second always flips bit 2, so it ends up as a or b. It leaves the input bits changed.

Expected: 1010 0000 0000 0000 ***

Patterns it teaches

  • Encoding tricks: the instruction set is spelled in its own data, two bits each.

Further

Also in Turing tarpits

Write your own in Run Convert a program from Two Four

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: two-four.

Command line

shib run two-four -e '11' --input '1'
shib manual two-four

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/two-four.js

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

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