Brainf*ck

WARNING: Offensive language ahead! That is, if you’re offended by a completely logical name that makes eloquent usage of the English language.

Brainfuck is just about the most awesome programming language ever invented. It consists of only eight commands, but is still Turing complete. So what are these infamous eight commands?

Imagine an array of bytes, and a single pointer that moves along these bytes.

> move the pointer to the right
< move the pointer to the left
+ add 1 to the value under the pointer
– subtract 1 from the value under the pointer
, take one byte of input
. print a byte as output
[ if the byte at the pointer equals zero, skip to the matching ]
] if the byte at the pointer is not zero, go back to the matching [

[ and ] act like a while loop:

while (byte != 0) {

}

It is so tiny, and yet this little language can do so much. Anything you can do in another language, you can do in Brainfuck. Jon Ripley even wrote a text-based game in Brainfuck. That’s crazy. The first few lines of the code look like this:

[-][.]>+[>[-]+[>[-]>>>>>>>[-]+>>>>[-]<<<>>>+<<<<-]<<<<<<>>>>>>[-]>>>>>[-]<<<<>>>>+<<<<<-]<<<<<<>>>>>>[-]>>>>>>[-]<<<<
<>>>>>+<<<<<<-]<<<<<<<>>>>>>>>>>>>>>[<<<<<<<<<<<<<<<>>>>>>>>>>
>>>>>-]<<<<<<<<<<<<<<<[-]+[>[-]>>>>>>>[-]>>>>>>>>[-]<<<<<<<
>>>>>>>+<<<<<<<<-]<<<<<<>>>>>>[-]>>>>>>>>>[-]<<<<<<<<>>>>>>>>+<<
<<<<<<<-]<<<<<<>>>>>>[-]>>>>>>>>>>[-]<<<<<<<<<>>>>>>>>>+<<<<<<<<
<<-]<<<<<<>>>>>>[-]>>>>>>>>>>>[-]<<<<<<<<<<>>>>>>>>>>+<<<<<<<<<<
<-]<<<<<<>>>>>>[-]>>>>>>>>>>>>[-]<<<<<<<<<<<>>>>>>>>>>>+<<<<<<<<
<<<<-]<<<<<<>>>>>>[-]>>>>>>>>>>>>>[-]<<<<<<<<<<<<>>>>>>>>>>>>+<<
<<<<<<<<<<<-]<<<<<<>>>>>>[-]>>>>>>>>>>>>>>[-]<<<<<<<<<<<<<>>>>>>

And there are 30,000 lines of this. Wow.

Advertisements
  1. phynnboi
    September 30, 2009 at 3:49 am

    I look forward to seeing your implementation of your keyboard layout program in Brainfuck. 😛

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: