CTFuck

From Esolang
Jump to navigation Jump to search

CTFuck is a turing complete esolang created by User:Pro465, based on a tag system, with I/O support. this is kinda simliar to Boolfuck, in that it operates on bits and has I/O support. however, CTFuck is based on a tag system.

The reference implementation along with examples are here.

Commands

supported commands are:

command operation
$ pop 1 bit off the front of queue
0 push 0 to the back of queue
1 push 1 to the back of queue
: duplicate bit at the front of queue, and push it to the back of queue
. output the bit at the front of the queue
, get the next bit of input and push it to the back of the queue
[..|..] see note

any character other than these are ignored.

Turing Completeness

CTFuck is turing complete. To prove this, we can take a similar path to how BCT was proved turing complete: we can translate each CT (we are using the same language the BCT page used) command to an equivalent sequence of commands in CTF.

CT command CTF Equivalent
<program end> [1|1]
0 0
1 1
; \n$[|<current line number + 1>]

...or we can just compile boolfuck to it

Sample Programs

Cat

  0
  $,.[1|1]

Truth Machine

,[|3]
    $1010.$...$..$..[|2]
    $010....$..$..

Hello world

0...$1.$0..$1.$0.
$1.$0.$1.$0..$1..$0.
..$1..$0.$1..$0.
..$1..$0.$1..$0.
$1....$0.$1..$0.
..$1..$0.$1.$0..
.....$1.$0..
$1...$0.$1...$0.
$1....$0.$1..$0.
.$1.$0..$1...$0.
..$1..$0.$1..$0.
..$1.$0..$1..$0.
$1.$0....$1.$0..
.$1.$0.$1.$0....

Notes

IO endianness

Like BoolFuck, IO in CTF is little-endian.

The [if_num|else_num] command

it takes two numbers in base-10 format, separated by `|` (pipe symbol).

when it is executed, it checks the bit at the top of the queue; if it is 1 it calls goto(if_num), otherwise it calls goto(else_num).

goto(n) is defined as follows:

   if n == 0 || n == "":
       pass
   else:
       jump to the first command in line n

Halting

execution is halted when either:

  1. the interpreter reaches the end of the program source.
  2. the interpreter tries to execute one of the following commands and the queue is empty:
  • [..|..]
  • $
  • .

See also

Other languages operating on bits (implemented only):