Page 1 of 1

brainf*ck

Posted: Sat Jun 09, 2012 8:31 pm
by antiloquax
Another forum member mentioned this language and I was intrigued.
It was developed in 1993 by Urban Müller on the Amiga.
It is a Turing-complete language with only 8 commands:

Code: Select all

<>,.[]-+
You can read more on wikipedia or on Brian Raiter's fun website, muppetlabs.
Basically, you have an array of 30000 cells. The instructions '<' and '>' move backwards and forwards along the array. '+' and '-' add or subtract one from the value held in the cell (they are initialised to zero). ',' is to input a character and '.' outputs to the screen. '[' and ']' allow you to do loops.
For instance:

Code: Select all

+++[>+++<-]
would increase the value of the first cell to 3, then move forwards one, add one to that cell and return to the original cell, decrementing it by one. When the first cell gets to zero, the loop terminates.
It's just for fun!
Anyway, I couldn't resist putting it on my RPi.
I used Urban Urban Müller's "Portable Brainf*ck Interpreter". You can download the source code here. Or you can get the binary I compiled here.
Here's a screenshot of me using the interpreter and then feeding a program to it.
The little bit of code I typed in:

Code: Select all

,++.
gets an input, adds 2 and the prints the character (so 'a' becomes 'c').
After that I fed this program to pbi. And, as you can see, it prints out my username.

Code: Select all

# brainfu*k program that prints my username

# The first line uses a loop to make the second cell hold the value 100
# Then we take away 3 to get 97 (the ascii value for 'a') 
# Then this is printed
# You can work out the rest!
++++++++++[>++++++++++<-]>---.
<+++++[>+++<-]>--.
++++++.
<+++[>----<-]>+.
+++.
+++.
++.
++++.
<+++++[>----<-]>.
<++++++[>++++<-]>-.
<++++++++++[>-----------<-]>.
If you are writing in brainf*ck, anything that's not an instruction is treated as a comment. So be careful not to use those 8 characters in your comments.
Image

Re: brainf*ck

Posted: Sat Jun 09, 2012 8:42 pm
by ukscone
Last year I ported/built a different brainf**k interpreter and some examples if you want to play with another version

http://russelldavis.org/RaspberryPi/bf (interpreter)
http://russelldavis.org/RaspberryPi/bf.1 (man page)
http://russelldavis.org/RaspberryPi/bf_examples/ (examples)

Re: brainf*ck

Posted: Sat Jun 09, 2012 9:01 pm
by antiloquax
That's great. I've had a look at a few different implementations. I'll check yours out!
mark

Re: brainf*ck

Posted: Sun Jun 10, 2012 9:27 am
by andyl
You can spend many an hour with esoteric programming languages. There is even a wiki for them http://esolangs.org/wiki/Main_Page - there are a few hundred languages listed. Including a number with only one instruction - the ultimate RISC.

Re: brainf*ck

Posted: Sun Jun 10, 2012 11:46 am
by antiloquax
Hi andyl - yes it was your mention of brainfu*k that led me to have a look at it.
The esoteric languages site you mentioned it good.
I MUST not spend too much time on these, however - I have a lot of properly useful languages to learn!