Henry el navegador
Brainfuck is a Computer programming language minimalist, invented by Urban Müller in 1993. It draws its name from the union of two English words, brain (brain) and fuck (foutre), transparent allusion to the expression " to masturbate the cerveau". This not very flattering vocabulary was worth to him besides to be written under other more prudish orthographies, such as Brainf*ck, Brainf *** or BF.
Presentation of the language
The objective of Müller was to create a simple computer programming language, intended to function on a Machine of Turing, and whose Compilateur would have most reduced possible size. The language is indeed satisfied only eight instructions. Version 2 of the original compiler of Müller, written for the Amiga, weighed itself only 240 Octet S, the current version being satisfied with 171 Octet S. the brainfuck is however a Turing-complete language , which means that, in spite of appearances, it is theoretically possible to write any computer program in brainfuck.
The counterpart is that, perhaps as its name does not suggest it for an not-english-speaking, the language brainfuck produces programs difficult to include/understand. It follows a model of simple machine, consistent in a table of bytes initialized to 0, a pointer on the table (positioned on the first byte of the table) and of two files of bytes for the entries and exits.
Instructions
The eight instructions of the language, each one coded by only one character, are the following ones:
(Alternatively,] can be defined by “turns over to the correspondent”. The formulation is shorter, but less symmetrical and less effective in time. The choice of one or the other of these two syntaxes does not influence the final behavior of the program.)
(A third equivalent version, though less considered, is: mean “change with the corresponding instruction”, and] means “turns over to the instruction after the correspondent if the pointed byte is different from 0”.)
The programs brainfuck can be translated into C by using following substitutions, by considering that ptr is of the type unsigned char*:
Examples
Hello World!
The following program posts traditional “Hello World! ” and a new line with the screen:
++++++++++
By preoccupation with a legibility, the code was divided into several lines and of the comments were added. Brainfuck regards as being comments all the characters except
++++++++++>++.>+.+++++++. +++.>++.<<+++++++++++++++.>.+++. ------. --------. >+.>.
The first line initializes
The following line moves the pointer towards
“being to it the seventh letter of the alphabet after “E”, to obtain “it is necessary to add 7 (
“O” is the third letter of the alphabet after “, one thus increments
The remainder of the program functions according to the same principle. For spaces and the letters in capital letter, in fact other cells of the table are selected and incremented.
The byte is décrémenté (buckles) until its value reached 0.
Post with the screen a character entered to the keyboard.
Buckle posting the characters entered to the keyboard. The end of the seizure is announced here by one 0 (the implementations can differ on this point).
A version improved of the preceding loop, in which the characters seized by the user are stored in a table for a future use, by moving the pointer each time.
Either Table = 2 and Table = 8, “” begins the loop, “-” and Table [0 = 1, “>” one points on byte 1, “+” and Table = 9, “]” one starts again.
At the end, there will be Tableau well = 0 what stops the loop, and Table = 10.
This program takes a tiny character in entry and the met in Majuscule. The entered key stops the seizure (code 10 in Brainfuck in the majority of the compilers).
At the beginning, one recovers the first character (,) and one withdraws 10 immediately to him (10 times -). If the user pressed on entry, there are 0 in the pointed byte and the instruction of loop (change at the end of the program.
If the entered character is not 10, it is considered that it is a small letter and one enters the loop, where one will withdraw the number 22 to him (22 times -), which will make 32 in all, 32 being the numerical difference between the small letter and the same letter in Majuscule in ASCII code.
The character is posted, then a new character is recovered, and again 10 are withdrawn to him. The program returns then at the beginning of the loop: if the key which the user validated entered (10), the loop stops, if not it continues.
This program adds 2 numbers with only one figure and posts the result if this one has also one figure:
(Maintaining the things will be a little more complicated. We will refer to the bytes of the table as follows: , etc)
The first number entered, and one withdraws 48 to him to have his decimal value (the ASCII codes for figures 0-9 are 48-57). That is done by putting 6 in and by using a loop to withdraw 8 of as much time than in, that is to say 6 X 8 = 48. It is a more convenient method to add or withdraw great numbers to put 48 times “-” in the program. The code which does that is:
Then, one recovers the sign + which one puts in, then the second figure which crushes the sign +.
The following loop
Then the pointer is given on, which is posted (is now has + (B + 48), since B was not corrected; what is identical to (+ b) has + 48, quiest-EC-that one wants). The pointer is then moved on, which contains the entered key, that one posts. The execution is finished.
Like the precedent, but carries out a multiplication, not an addition.
The first number entered, the asterisk and the second number in and the 2 numbers are corrected in their withdrawing 48 (note: there is not that only one loop of 8 iterations to withdraw 6 to the two numbers with each iteration!).
Then one enters the loop of principal multiplication. The basic idea is that from each loop one withdraws 1 of and one adds in the cumulated total kept in (3 * 2 = 2 + 2 + 2). In particular: the first loop cumulates in and, while giving to 0. (It is the basic manner to duplicate a number.) The second loop gives in, while giving to 0. Then one décrémente and one is at the end of the principal loop. At the exit of this loop, 0 contain, still contain the second number, and contain the product of the 2 numbers (to keep the value, it is enough to add it in to each iteration of the principal loop, then to move the value of in.)
Example: 3 * 2
Then, it does not remain any more that to add 48 to the product, to recover the key entered, and to post the product in ASCII and the entry who has just been stored.
The macros-definitions below define techniques making it possible to find structures or instructions used usually in Algorithmique or in the computer programming languages. They facilitate the creation of Brainfuck programs. There exist implementations of Brainfuck accepting the definition of macros.
The symbols like Displacement of the pointer
The macro Addition of a constant
One can note that, as each cell of the table is a byte, the instruction “-” superfluous and is perhaps replaced by 255 “+”. Same manner, 30 000 cells forming a circular table, “<” perhaps replaced by 29 999 “>”. That would reduce the language to six instructions.
Brainfuck has many descendants. The majority are satisfied to make the code even more inextricable (for example f*ckf*ck, it
language pi, or Ook! describes below); others add real functionalities
(the languages Fm, Nanopond).
The language Ook is an alternative of brainfuck. It is a Turing-complete language , conceived to be perfectly readable by a Orang-outan, in reference to the character of the librarian of the universe of the Disc-world of Terry Pratchett.
Hello world in Ook
Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook? Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook? Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook? Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook? Ook? Ook! Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook? Ook! Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook. Ook? Ook? Ook! Ook? Ook. Ook! Ook! Ook! Ook! Ook! Ook! Ook! Ook.
+-<>. . The actually compiled code can thus be reduced to the following line:
a = 10 by simple successive increments from 0. The loop of lines 2 to 4 defines in an effective way the initial values of the table: a = 70 (near to 72, the code ASCII of the character “H”), a = 100 (near to 101 or “E”), a = 30 (near to 32, space) and a = 10 (new line). The loop functions by multiplying the values of a, 10, by 7,10,3, and 1, qu ' it stores in the close cells. When the loop is completed, has is worth zero. >++. then moves the pointer with a, which contains 70, adds to it 2 (72 being the code ASCII of the capital letter “H”), and posts it.
a and increments it of 1, the result, 101, corresponding to “E”, which is then posted.
+++++++) to a and to post it twice.
a three times before posting the result.
Restoring of the pointed byte
Input/output of a character
.
Simple loop
,
Handling of pointer
>,
Addition
This code adds the current byte (while destroying it, it is thus given to 0) to the following byte.
Conditional instructions
,----------
Addition
, >++++++, <.>.
4+3
7
>++++++
>++++++ to put 6 in, then one tackles the loop, “<” to return on, one withdraws 8, “>” one passes by again on, that one décrémente and one turns over in the loop. The loop is then carried out 6 times, until is equal to 0.
adds indeed the number of the second cell in the first cell and gives to zero. To each loop, he adds 1 in and withdraws 1 of; thus ends up being to 0. All that was added was withdrawn from. Then the entered key is put in. (Note: there was no control of the entries.)
Multiplication
, >, >++++++++
<<>><<<-]
>>>++++++, <.>.
Brainfuck Macro-definition
a, b or s represent each one a different byte in table report. The symbol t indicates a byte used temporarily for the needs for macro. The symbol s represents a byte used as source and d a byte used like destination.
to (a) consists in moving the pointer in table report on the level of the byte a. It is obtained with a series of < or of > .
Macro addCst (N) adds to the byte pointed the value N . It is obtained with a series of + or - according to the sign of N .
zero (m): to (m)
move (S d): to (S) to (d)+ to (S)
move2 (S d1 d2): to (S) to (d1) + to (d2) + to (S)
copy (S D T): move2 (S D T) move (T S)
if (a): to (a)
: endif (a): zero (a)]
ifelse (T has): to (T) + to (a) to (T) -
: else (T has): zero (a)] to (T)
: endelse (T): to (T) -]
for (S): to (S)
: next (S): to (S) -]
swap (B T has): move (T has) move (B a) move (T b)
Comment
Alternatives
Ook!
External bonds
Random links: Precession of the equinoxes | Iatmul | Trilogy of Qatsi | Armilla | Julija Schamschurina | Henry_le_navigateur