Welcome dear guest! Very Happy

To start posting and being part of the community, you simply need to register an account or log into an existing one.

Be sure to check out disposable e-mail services, in case you prefer using one for this site instead of your legit address: http://10minutemail.com/10MinuteMail/

If you do not wish to register at all, that's fine but there will be more advertisements. :/

You can see and download all content provided for regular members even without an account!

Your contributions will be greatly appreciated though, give it a shot and register today! thumbsup

Gaming, Modding & Programming

Important reminders:

- Click *HERE* for advanced forum search or check out the text field below on the front page for Google before posting
- NO support via private message (use the forum)
- Write meaningful topic titles
Site Translation

Display results as :

Rechercher Advanced Search

February 2018

Calendar Calendar

Country Statistics
Free counters!
LaTeX Generator

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 BrainFuck Explained Simply on 1/18/2016, 9:58 am


Admin & Writer
BrainFuck is what is known as an esoteric programming programming language, which is sometimes shortened to esolang. And BF or Brain**** for people who do not like to speak profanely. It is the most popular esoteric programming language.

"It is a programming language designed to test the boundaries of computer programming language design, as a proof of concept, as software art, or as a joke. Usability is rarely a goal for esoteric programming language designers—often it is quite the opposite. Their usual aim is to remove or replace conventional language features while still maintaining a language that is Turing-complete.

I suggest reading up on esoteric programming languages, but most importantly BrainFuck before you continue on reading.

The main concept of an esolang is just to have fun learning it and to confuse the hell out of your cognitive abilities. But once you are well familiar with it and can write things easily, you should show off to people who are computer inclined (VERY good at computers) and you'll amaze them.

Let's start, shall we?

I will colour keywords in red that you will need to remember!

BrainFuck is represented by an array with 30,000 cells initialized to zero and a data pointer pointing at the current cell.

There are eight commands:
+ : Increments the value at the current cell by one
- : Decrements the value at the current cell by one
> : Moves the data pointer to the next cell (cell on the right)
< : Moves the data pointer to the previous cell (cell on the left)
. : Prints the ASCII value at the current cell (i.e. 65 = 'A')
, : Reads a single input character into the current cell
[ : If the value at the current cell is zero, skips to the corresponding ]
Otherwise, move to the next instruction
] : If the value at the current cell is zero, move to the next instruction
Otherwise, move backwards in the instructions to the corresponding [
[ and ] form a while loop. Obviously, they must be balanced

If you're familiar with Wii coding, you should know that a placeholder is well, a place for the code to hold a user defined value. In BrainFuck, a cell is pretty much the same thing, except for the fact that it holds a value that the user writes by code instead of just inserting a Hexadecimal value into the code itself. If you don't understand, keep reading.

As said before, each cell is initialized to zero. Meaning it starts off at zero and further instructions (see above) will either increase and or decrease the value depending on the instructions laid out by the user. The lowest a cell can be, as far as I know, is zero, it can't go negative. Correct me, if I'm wrong.

BrainFuck code is read from left --> right, unlike normal languages like C++, Python, Bash, etc. where it's read from left --> right on one line, then when it reaches the end of the line, it runs that line of code and then jumps to the next line and does the same thing until it reaches the end. Basically, it is ran the opposite of Binary, Decimal, Octal and Hexadecimal (right to left). So, if you are familiar with a numbering system, such as Decimal, which you should be if you're human, imagine you're writing different numbers, but you're doing it backwards and each digit is a piece of code which coincides and plays out with the entire code. When pieced together in a certain way, it does something, hopefully not an error though.

Read over the above codes and get to know them and understand them. There's only eight of them, so it shouldn't be too hard to remember, in fact, it should only take you maybe a few minutes at the most to remember them. If you don't have that good of a memory and if you can't remember those 8 simple, relatively similar bits of instructions, there's something wrong with you, but good thing you can just write them down and use them as a reference for when you're writing BrainFuck code.  Wink   Shocked

What programmers used to do back when people first started programming and computer classes in high school would teach you this, is to make a flowchart.

Here is an example of a flowchart I got from Wikipedia.

As you can see, a flowchart is like an intuitive instruction book, but instead of reading pages, you're reading a diagram and answering questions. You continue on to the next question (bubble) and answer it and move on to the next based upon your answer and so on and so forth until you come to the end (solution, if fixing something such as a lamp or the end of the program, if building a program).

I don't prefer to use flowcharts, as, to me, they take up too much time drawing them out. And even though you can get simple programs and just drag and type, such as "Ideas" or some shit like that (what my high school used), even that takes time and you would be fiddling around with it to make it perfect. Why have an app for flowcharting when you can write out in plain English or English statements with acronyms (easiest way) in Notepad? And besides, they're only useful if your program is working like a human (If, While, Else, etc.)

Me? I prefer to use Notepad because it's easier to understand, cleaner and faster, among other things.

Anyways, here is a code that prints out the letter "A" In a language like Python you would type:

print 'A'

In BrainFuck, however, it is much more complicated than that, at least for people who are starting out in BrainFuck.

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

This code does the same thing as the above Python code; prints out the letter "A". Let's break it down!

First, it increments cell #1 to 6
Cell #1 will be used for looping
Then, it enters the loop ([) and moves to cell #2
It increments cell #2 10 times
Moves back to cell #1
Decrements cell #1
This loop happens 6 times (it takes 6 decrements for
cell #1 to reach 0, at which point it skips to the corresponding ] and
continues on).

I prefer to use simplicity when I do things, especially when I'm explaining something.

"If you can not explain it simply, you do not understand it well enough." ~Albert Einstein

It took me hours upon hours to figure out what they were trying to explain to me and other readers. I finally figured it out and decided to make this post to make it easier for people to understand. This is how I wrote it out and how I prefer to write things. It makes the world of understanding the concept of a code a hell of a lot more easier! It's like Pitman Shorthand, but for code.

Below I have written out in BrainFuck (and simplicity) the first two letters of my name (Andrew).

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

The Uppercase Letter "A"

Cur Cell #1
Cell #1 Increment 6 (+)
Cur Val Cell #1 6
Enter Cell #1 Loop ([])
Move to Cell #2 (>)
Increment Cell #2 10 (+)
Cur Val Cell #2 10
Decrement Cell #1 1 (-)
Repeat (<) until Cell #1 is Zero (])
Cur Val Cell #1 Zero
Cur Val Cell #2 60
Cur Cell (#1) Val Zero
Exit Loop ([] )
Move to Cell #2 (>)
Increment Cell #2 5 (+)
Output Val 65 DEC > ASCII
Print "A"

The Lowercase Letter "n"

Cur Cell #1
Cell #1 Increment 10 (+)
Enter Cell #1 Loop ([])
Decrement Cell #1 1 (-)
Move to Cell #2 (>)
Cell #2 Increment 10 (+)
Cur Val Cell #2 10
Repeat (<) until Cell #1 is Zero (])
Cur Val Cell #1 0
Cur Val Cell #2 100
Exit Loop
Move to Cell #2
Increment Cell #2 10
Cur Val Cell # 2 110
Output Val 110 DEC > ASCII
Print "n"

Now, hopefully, you understand how it works. This is the way I figured out how to understand BrainFuck; by writing it out in English code statements. I suggest you do the same. If this is still troubling you, do not give up! I will assist in helping you. A lot of people think it's hard as fuck, but it's not. I actually find this easier than normal programming languages, but that's just me. To be completely honest, it took me only 2 days to figure all this out. If you just invested about 30 minutes or so into reading this post over and over again, you will understand how to, at least, print things in BrainFuck.


Use this post instead of the link below, this is just where I got the instruction set and the difficult-to-understand guide to printing the letter "A" from.



ASCII / Decimal Chart:


If I need improvements on this guide, please suggest them to me, so I can make it easier for you and others to read and understand. Smile


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum