esolang

Linear bounded brainfuck

Brainfuck with a tape exactly as long as the input and the program put together.

PythonshellDebugwindow, 2020 · Turing complete: with unbounded memory · ●○○ easy · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: Hello, World!

The idea

PythonshellDebugwindow made Linear bounded brainfuck in 2020, to make brainfuck a linear bounded automaton. Such a machine may only use memory in proportion to the size of what it is given. In this language that size is the length of the input plus the length of the program, and the tape has that many cells and no more.

Read the story

There is no ,. The input is written on the tape before the run, one byte a cell, and the cells after it start at 0. Stepping off either end of the tape is an error that ends the run.

The machine

CharDoes
> <Move the pointer right or left, an error past either end
+ -Add or take 1 from the cell, which wraps at 256
.Print the cell as a byte
[ ]Loop while the cell is not 0

The pointer starts on the first cell, which holds the first byte of the input. Every other character is a comment, but it still counts towards the length of the tape.

Example

The cat prints the cells until it finds a 0.

The cat prints the cells until it finds a 0. On an input of length n the tape has n + 4 cells, so the cat stops in time.

This cat then marches right, adding 1 to each cell, until it falls off the end of the tape. The input is printed before the error.

Expected: abc

The truth machine copies the input to two cells and takes 48 from one of them. On 1 it prints the other cell, the character 1, forever. On 0 its last . prints the byte 0 rather than the character 0.

Patterns it teaches

  • Turing tarpit: brainfuck without its input command, on a fixed amount of memory that makes it weaker than a Turing machine.

Further

Linear bounded brainfuck builds on Brainfuck.

Brainfuck derivatives

Write your own in Run Convert a program from Linear bounded brainfuck

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: linear-bounded-brainfuck.

Command line

shib run linear-bounded-brainfuck -e '[.>]' --input 'Hello, World!'
shib manual linear-bounded-brainfuck

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/linear-bounded-brainfuck.js

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

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