A language that shall not be named!!!

2013 has gone just like that. So, I thought I could post something before it leaves us forever. I’ve chosen “Brainfuck” for our today’s discussion. This language is something I’ve always wanted to write in my blog…

It’s an esoteric programming language, and if you have some idea on programming, it’s probably the easiest one I’ve ever seen. Because, it’s got only eight commands < > + – , . [ ]. As it’s esoteric in nature, it can’t be used for our regular programming purposes. But, it can always be used to convey some information like, output a simple “Hello world!” program, or say, throw Fibonacci numbers.

And, I meant “easiest” in the sense, that it’s the easiest to write. If you take understanding the program into account, life is really tough. Because, a brainfuck code is very difficult to visualize, being constructed entirely with eight symbols (and visualized only by using ASCII character encoding).

The program uses an array of a series of 30,000 byte cells, all initialized to a null (zero) value at the start of the program. A pointer, initialized to the beginning of the array, is made to move through these cells. Here’s a representation of the array’s initial state…

The numbers 0, 1, 2… denote the addresses of each cell, and the pointer is initialized to the first cell.

  • The angle brackets handle that pointer’s motion. “>” moves the pointer to the right, while “<” moves it to the left.
  • + and symbols are used to increment or decrement the value of the cell at the pointer’s location.
  • . (period) and , (comma) symbols are equivalent to “print” and “scan” commands, with the difference that ASCII encoding is used. The former prints the value stored in the cell, while the latter takes input into the cell.
  • The square braces [ ] perform a loop. The loop is continuously performed until the value of the operating cell (which is being decremented) becomes zero.

There are Brainfuck code generators and decoders allover the internet. So, you can make use of them to do the job, instead of you trying hard to visualize the thing.

Okay, here’s a code…


What’s happening here?

The first eight lines initialize the first five cells, with the required values for writing the program, whereas the last 14 lines shift the pointer here and there, modify the cell values, and print the output characters one by one.

The first line has 10 pluses, which means that the cell where the pointer is located, (zeroth) is incremented 10 times, leaving us with this…

Then, comes the loop. Here, I’ve chosen the first, second, third and fourth cells to be incremented, while simultaneously decrementing the zeroth cell (the “<<<<” causes the pointer to jump 4 cells, taking it to the zeroth cell). There should be a decrementing snippet, for the program to terminate the loop.

What I’ve written is simply this. Increment first cell – 7 times, second cell – 8 times, third cell – 9 times, and fourth cell – 3 times, by simultaneously decrementing the zeroth cell once. So, each time the cells #1, #2, #3, and #4 are incremented, the zeroth cell is decremented once. Hence, the loop goes for 10 times.

Now, the cells have the following values…

I should remind you that the output characters are ASCII equivalents. For instance, take the line next to the loop. “>++.” It shifts the pointer to the first cell, increments it twice and prints the character, which in this case is H. I’ll leave the latter steps for you to visualize the output by yourselves.

The conclusion is that all these jumps & bumps, when combined as a whole, lead to the phrase…


Yep. “Happy New Year” to all of my readers!!!

It’s been a productive year, I know. And, I had a good time writing posts. But, let’s forget all that today, and happily welcome 2014, with the hope that it’d be relatively much more productive than last time…

In addition, here’s another sweet sauce from a brainfuck enthusiast. You’d really love it!


Tagged: ,

Wanna 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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: