Fuckhard

From Esolang
Jump to navigation Jump to search
Fuckhard
Paradigm(s) imperative
Designed by User:Umnikos
Appeared in 2024
Computational class Turing-complete
Reference implementation Github gist
Influenced by brainfuck
File extension(s) .fh

Fuckhard is yet another brainfuck derivative, made by User:Umnikos. It aims to just be brainfuck but harder to use.

Language overview

Command Description
> Move the tape head to the right by one
< Move the tape head to its initial position
+ Set the current cell's value to 1
. Output the current cell's bit
, Input a bit. If it's 1, set the current cell's value to 1.
( Jump forward to the matching ) if the cell at the pointer is 1, halting if there's no matching ).
] Jump back to the matching [ if the cell at the pointer is 1, halting if there's no matching [.

Each cell can only hold a single bit, and once set to a 1 can never be reset back to 0. Therefore working with data requires its constant copying to new blank cells over and over. Furthermore, the < instruction goes all the way to the beginning of the array, so moving left involves going to the start and then going right again to where you want to be. The square brackets and the parentheses only need to match up among themselves and not with each other, allowing for very non-standard control flow if the programmer chooses to make use of that.

Examples

Truth machine

 ,[.]

Cat program

 [>,.+]

Cat 1s and halt on 0

 +([.)>,]

Add two numbers

Numbers are represented as N 1s terminated by a 0

 +([.)>,]+([.)>,].

Multiply two numbers

 +[>,]>+([<([.)>]>[>]+)>,].

Computational class

Fuckhard is Truing Complete because it can emulate a Bitwise Cyclic Tag system, which is Turing Complete. This is a Bitwise Cyclic Tag implementation by User:Olus2000:

Memory layout:
 - program queue data flag
 - program queue consumed flag
 - program queue data
 - data queue data flag
 - data queue consumed flag
 - data queue data

Input encoding:
 - program encoded as pairs of bits 10 for 0 and 11 for 1
 - a single 0 bit
 - data encoded as pairs of bits 10 for 0 and 11 for 1
 - a single 0 bit

Read program and data; expects at least 1 bit of program and data:
+>+>>>>>,[>>,>>>>,] <>>>+>+>>>>> ,[>>,>>>>,] <
Banch on the frst bit of program and consume it:
[[[[[<>[>>>>>>]+>
( If false delet first bit of data
  <[>>>>>>]+
  <>>>>[>>>>>>]+>.
  If not all data has been consumed then repeat
  >>>>]<>
  Otherwise spill over to the true branch
) >>>>> ( This will be false if coming into a true branch
  If true then it's complicated
  <[>>>>>>]+>>+
  Branch on the first bit of data
  <>>>>[>>>>>>]>
  ( If false just consume one bit of program and repeat
    <>[>>>>>>]+>
    ( Copy bit 0 at the end of program
      <[>>>>>>]+<]
    ) Copy bit 1 at the end of program
      <[>>>>>>]+>>+<]
  ) If true branch on first bit of program
    <>[>>>>>>]+>
    ( Copy bit 0 at the end of program *and* data
      <[>>>>>>]+ <>>>[>>>>>>]+<]
    ) Copy bit 1 at the end of program *and* data
      <[>>>>>>]+>>+ <>>>[>>>>>>]+>>+<]
)