Hello Fuck!

From Esolang
Jump to navigation Jump to search

Hello Fuck! is a brainfuck derivative by User:None1.

Memory Model

Hello Fuck! works on a string tape and a pointer initially pointing to the first cell. But every cell in the tape can only be two kinds of string: Hello and World. Initially, all the cells are Hello.

Commands

It has these commands:

Commands in Hello Fuck!
Command Meaning
* Negates current cell (if the current cell is Hello then set it to World, and vice versa)
< Moves the pointer to the left
> Moves the pointer to the right
, Input a string and stores it into current cell, if the string isn't Hello or World then do nothing
. Output current cell value followed by a space
[ If the current cell value is Hello, then jump to the matching ]
] If the current cell value is World, then jump to the matching [

And like brainfuck, other characters are NOPs.

Example Programs

Hello World

.*.

Cat Program (sort of)

*[>,.<]

It never terminates, but only echoes Hello and World in the input correctly (if the input has other strings other than, Hello and World, it might print either Hello or World).

Truth Machine (sort of)

,[.].

You use Hello for 0 and World for 1.

Computational Class

It's the same as brainfuck with bit cells, but Hello for 0 and World for 1, so it's probably Turing complete.

Interpreter

Original C++ implementation (input strings can be separated by any kind of whitespace):

#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int tape[1000000];
string table[2]={"Hello","World"};
signed main(){
	string code="";
	char c;
	while((c=getchar())!=EOF) code+=c;
	int ip=0,p=0;
	while(ip<code.size()){
		char cmd=code[ip];
		switch(cmd){
			case '*':{
				tape[p]=!tape[p];
				break;
			}
			case '>':{
				p++;
				break;
			}
			case '<':{
				p--;
				break;
			}
			case ',':{
				string s;
				cin>>s;
				if(s=="Hello") tape[p]=0;
				if(s=="World") tape[p]=1;
				break;
			}
			case '.':{
				cout<<table[tape[p]]<<' ';
				break;
			}
			case '[':{
				int loop=1;
				if(!tape[p]){
					while(loop){
						ip++;
						if(code[ip]=='[') loop++;
						if(code[ip]==']') loop--;
					}
				}
				break;
			}
			case ']':{
				int loop=1;
				while(loop){
					ip--;
					if(code[ip]=='[') loop--;
					if(code[ip]==']') loop++;
				}
				ip--;
				break;
			}
		}
		ip++;
	}
	return 0;
}

Here is the same interpreter compiled as a Windows executable.