Zfuck

From Esolang
Jump to navigation Jump to search

Zfuck is a minimal Turing-complete 3-command variation of Smallfuck discovered by User:PythonshellDebugwindow. It was developed independently of Nanofuck.

Memory

Like Smallfuck, Zfuck operates on a tape of bits, but unlike Smallfuck, Zfuck uses a left- and right-unbounded tape. The tape is initialized with the program's input as a binary number left- and right-padded with zeros, and the program's output is all previously and currently visited cells in the tape at the end of the program (if it halts) as a binary number.

The minimization process

We start out with Smallfuck's 5 commands.

><*[]

We can combine *> into } to get 4 commands.

}<[]

We can also define the empty loop [] to be a nop and merge ]< into ) to get 3 commands.

}[)

Simple translation to and from SmallfuckU

This version of Smallfuck has an unbounded tape. Let's call it SmallfuckU for the sake of brevity.

Zfuck SmallfuckU
} *>
[ [
) ]<
SmallfuckU Zfuck
> }[)}
< [)
* }[)
[ [
] )}[)}

Examples

Infinite loop

[}[))}[)}}[)[}[)}[))

Truth-machine

[}[)}[))

Interpreter in JavaScript

The first argument is the code and the second is the initial tape. Undefined behaviour for a negative cell pointer. Also severely golfed and memory-inefficient as a result.

var zfuck=(c,m)=>eval("var p=0;"+c.replace(/}/g,"m+=~0];m~p]=!m~p++];").replace(/\)/g,"}p--;").replace(/\[/g,"while(m[p]){").replace(/~/g,"[").replace(/{}/g,"break;"));

See also