Brainfuckn't
Two tapes of bits, and a pointer that can be any number of bits wide.
4gboframram · Turing complete: yes · ●●● hard · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
4gboframram made Brainfuckn't to be more frustrating than brainfuck, with an instruction set just as simple. The cells are single bits and there are two tapes. One pointer size holds for both pointers, and the bits under a pointer, as many as the size, are its region. A region reads as a number with the lower position as the more significant bit. To print a byte you widen the pointer to 8 bits; to test one bit you narrow it to 1.
Read the story
There is no increment. A region changes only by flipping it, by reading a byte into it, or by OR, AND or XOR with the region on the other tape.
The machine
| Command | Does |
|---|---|
> < | Move the first pointer right or left |
} { | Move the second pointer right or left |
+ - | Widen or narrow both pointers by one bit |
~ | Flip every bit of the first region |
| & ^ | OR, AND or XOR the second region into the first |
@ | Swap the two tapes with their pointers |
. , | Print the first region as a byte or as a decimal number |
* | Read a byte into the first region |
[ ] | Loop while the first region holds a 1 |
_ | Print both tapes, for debugging |
The pointers start 1 bit wide, as the cat reaches 8 with seven +. The specification's table gives ^ as AND a second time, but its truth machine needs XOR, so ^ is XOR in this implementation. At the end of input * reads 0.
Example
The Hello World program has 104 characters.
The Hello World program has 104 characters. Its author calls it bit fuckery.
The truth machine flips the bits at positions 2 and 3 to make 00110000, the code of 0, reads the input onto the other tape and XORs the two. On 0 the result is all 0, so the loop is skipped and the 0 is printed once. On 1 it narrows the pointer to a single 1 bit and prints it as a number forever.
Eight bits all flipped to 1 print as the number 255. _ shows each tape with its region in brackets.
The cat, +++++++~[*.], flips 8 bits so the loop can start, then reads and prints a byte each turn. It stops after the 0 it reads at the end of the input, which it prints too.
Patterns it teaches
- Turing tarpit: with the size kept at 1 and only
[]~><, it is brainfuck with bits for cells. - Turing completeness: the specification shows it through that bit brainfuck, which stays Turing complete with loops nested only 2 deep.
Further
See also
Also in Turing tarpits
Write your own in Run Convert a program from Brainfuckn't
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: brainfuckn-t.
Command line
shib run brainfuckn-t -e '+++++++~[*.]' --input 'cat '