Migraine for a great good
by Ankit Shukla
☠ at your own risk ☠
Esoteric programming language
"An esoteric programming language is a computer programming language designed
to experiment with weird ideas, to be hard to program in, or as a joke, rather than for practical use."
Today's Menu
- Turing-completeness
- Brainfuck
- Piet
- Fractran
Turing machine
Can solve all possible algorithmic computations- Infinite ribbon of (finite state) cells
- Left / right movement
- Choice and action on current cell
Turing complete languages
" A given programming language is said to be Turing - complete if it can be shown that it is computationally equivalent to a Turing machine."
Brainfuck
♥ Invented in 1993 by Urban Müller
♥ Goal : Turing-Complete language which needs a minimal compiler only.
♥ Müller's Amiga compiler was 240 bytes in size
It consists of 8 operators
Basics
✈ The idea behind Brainfuck is memory manipulation.
✈ You are given an array of 30,000 1byte memory blocks
✈ A Brainfuck program has an implicit byte pointer,
called "the pointer" initially all set to zero.
✈ Within this array, you can increase the memory
pointer, increase the value at the memory pointer, etc.
Operators
> becomes ++p;
< becomes --p;
+ becomes ++*p;
- becomes --*p;
. becomes putchar(*p);
, becomes *p = getchar();
[ becomes while (*p) {
] becomes }
ツ Test loop ⇒ [ ]
ツ Byte IO ⇒ , .
♛ Rules ♛
® Characters besides the 8 operators should be considered comments.
® All memory blocks on the "array" are set to zero at the beginning of the program.
® And the memory pointer starts out on the very left most memory block.
® Loops may be nested as many times as you want.
But all [ must have a corresponding ].
Examples
[-]
Enter a loop that decreases the value stored at the current memory pointer
until it reaches zero, then exits the loop.
+++++[-]
C ➳ *p=+5;while(*p != 0){ *p--; }
Incrementing the current memory ptr value to 5, then entering a loop that dec the value located at the memory ptr till it is zero, then exits the loop.
More examples
,[.,] Echo ☂ EOF returns 0
>>>++
This will move the memory pointer to the fourth memory block, and increment the
value stored there by 2.
memory blocks ------------- [0][0][0][2][0][0]... ^ memory pointer
>>>>++<<+>>+
memory blocks ------------- [0][1][0][3][0][0]... ^ memory pointer
Hello World
+++++ +++ Set Cell #0 to 8
[
>++++ Add 4 to Cell #1; this will always set Cell#1 to 4
[ as the cell will be cleared by the loop
>++ Add 4*2 to Cell #2
>+++ Add 4*3 to Cell #3
>+++ Add 4*3 to Cell #4
>+ Add 4 to Cell #5
<<<<- Decrement the loop counter in Cell #1
] Loop till Cell #1 is zero
>+ Add 1 to Cell #2
>+ Add 1 to Cell #3
>- Subtract 1 from Cell #4
>>+ Add 1 to Cell #6
[<] Move back to the first zero cell you find; this will
be Cell #1 which was cleared by the previous loop
<- Decrement the loop Counter in Cell #0
] Loop till Cell #0 is zero
hELLO wORLD
The result of this is:
Cell No : 0 1 2 3 4 5 6
Contents: 0 0 72 104 88 32 8
Pointer : ^
>>. Cell #2 has value 72 which is 'H'
>---. Subtract 3 from Cell #3 to get 101 which is 'e'
+++++ ++..+++. Likewise for 'llo' from Cell #3
>>. Cell #5 is 32 for the space
<-. Subtract 1 from Cell #4 for 87 to give a 'W'
<. Cell #3 was set to 'o' from the end of 'Hello'
+++.----- -.----- ---. Cell #3 for 'rl' and 'd'
>>+. Add 1 to Cell #5 gives us an exclamation point
>++. And finally a newline from Cell #6
⚥Joke Killer !
Brainfuck
By ashleel baba
Brainfuck
- 1,871