CTFuck
Bits in and bits out, as in Boolfuck, but the memory is a queue that works like a tag system.
Pro465 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Pro465 based CTFuck on a tag system. Like Boolfuck, it works on single bits and reads and prints them. The memory is a queue of bits. Commands push bits at the back, pop them from the front, print the front bit and read input bits. The only jump looks at the front bit and goes to a numbered line of the program.
Read the story
The specification proves it Turing complete by translating cyclic tag. Each production goes on its own line, which starts with $[|n]. That drops the front bit and skips the rest of the line, where the production's bits are pushed, when the new front bit is 0.
The machine
| Command | Does |
|---|---|
$ | Pop the front bit |
0 1 | Push a bit at the back |
: | Push a copy of the front bit |
. | Print the front bit |
, | Read a bit and push it |
[a|b] | Jump to line a if the front bit is 1, to line b if it is 0 |
A line number of 0, or none at all, means no jump. Lines count from 1. The program halts at its end, or when $, . or a jump meets an empty queue. Eight bits make a byte, lowest bit first, both ways.
Example
The Hello world keeps one bit in the queue.
The Hello world keeps one bit in the queue. $1. swaps it for a 1 and prints it, and each further . prints it again. The first line prints 0, 0, 0, 1, 0, 0, 1, 0, which lowest bit first is 72, an H.
The truth machine reads one bit, the lowest bit of the character. For 0 it jumps to line 3, which prints the eight bits of the character 0 and ends. For 1 it goes on to line 2, which prints the bits of 1 and jumps back to line 2 forever.
The cat jumps to line 1 for each next bit. With lines counted from 1, as the truth machine needs, that line pushes another 0 and the cat prints a 0 after each bit it reads; it works only with lines counted from 0.
Patterns it teaches
- Tag systems: cyclic tag, one production per line.
- Turing tarpit: six commands and one jump.
Further
See also
Queue-based
Write your own in Run Convert a program from CTFuck
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: ctfuck.
Command line
shib run ctfuck -e ',[|3]
$1010.$...$..$..[|2]
$010....$..$..' --input '0'shib manual ctfuckSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/ctfuck.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org