esolang

Binerdy

Only 0 and 1. A command is how long the digits keep alternating.

Bas · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 4 known programs · Test method

Run it

Expected: 0

The idea

Bas made Binerdy to recall the days when computers only understood zeroes and ones. A program is a string of 0 and 1, read as runs that alternate. Where a digit repeats, a run ends, and its length is the command. So 0101011010011101011 cuts into 010101 1010 01 1 10101 1 and runs the commands 6, 4, 2, 1, 5 and 1. It does not matter whether a program starts with 0 or 1, and any other character is an error.

Read the story

Underneath is a small stack machine with 13 commands. The Hello, world! program takes 1,143 digits, mostly runs of 2 and 3 that count a byte up and down. Its quine is the single digit 0. One run of length 1 pushes a 0, and Binerdy prints whatever is still on the stack when the program ends.

The machine

RunNameDoes
1initPush 0
2, 3inc, decAdd 1 to the top, or take 1 from it
4, 5add, subPop the top and add it to the value under it, or take it from it
6labelPop the top and mark the next command with it
7, 8je, jnePop a label and a value, and jump if the value equals (or differs from) the one under it
9inputPush a number read from the input
10swapSwap the top two
11, 12print, charPrint the top as a character, or as a number
13remRemove the top

Values are bytes from 0 to 255 and wrap around. The specification leaves a few things open, and this implementation takes the plainest reading. Input reads a whole number, since the truth machine compares it with 1. A jump lands on the command after its label. The stack left at the end is printed top first, as numbers with nothing between them.

Example

The second program is the runs 1, 2, 2, 2, 12 and 13.
Expected: 3
Expected: 7
Expected: 0

The second program is the runs 1, 2, 2, 2, 12 and 13. It pushes 0, adds 1 three times, prints 3 and removes it, so nothing is left to print at the end. The cat from the specification is input, char and rem.

The truth machine reads a number, marks label 0 and prints the number. Then it pushes 1 and the label, and jumps back while the number still equals 1. On 0 it prints 0 once, on 1 it prints 1 for ever.

Patterns it teaches

  • Encoding tricks: an ordinary stack machine hidden in the run lengths of two digits.
  • Stack machines: every command works the top of one stack.
  • Quine: printing the leftover stack makes 0 print itself.

Further

Stack-based

Write your own in Run Convert a program from Binerdy

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run binerdy -e '0'
shib manual binerdy

Source

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

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

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