diff options
-rw-r--r-- | brainfuck.html.markdown | 79 | ||||
-rw-r--r-- | hu-hu/go.html.markdown | 2 | ||||
-rw-r--r-- | php.html.markdown | 10 |
3 files changed, 89 insertions, 2 deletions
diff --git a/brainfuck.html.markdown b/brainfuck.html.markdown new file mode 100644 index 00000000..2b7ce4db --- /dev/null +++ b/brainfuck.html.markdown @@ -0,0 +1,79 @@ +--- +language: brainfuck +contributors: + - ["Prajit Ramachandran", "http://prajitr.github.io"] +--- + +Brainfuck is an extremely minimal programming language (just 8 commands) and +is Turing complete. + +``` +Any character not "><+-.,[]" (excluding quotation marks) is ignored. + +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. + +Let's look at some basic Brainfuck programs. + +++++++ [ > ++++++++++ < - ] > +++++ . + +This program prints out the letter 'A'. 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, and +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). + +At this point, we're on cell #1, which has a value of 0, while cell #2 has a +value of 60. We move on cell #2, increment 5 times, for a value of 65, and then +print cell #2's value. 65 is 'A' in ASCII, so 'A' is printed to the terminal. + + +, [ > + < - ] > . + +This program reads a character from the user input, copies the character into +another cell, and prints out the same character. + +, reads in a character from the user into cell #1. Then we start a loop. Move +to cell #2, increment the value at cell #2, move back to cell #1, and decrement +the value at cell #1. This continues on until cell #1 is 0, and cell #2 holds +cell #1's old value. Because we're on cell #1 at the end of the loop, move to +cell #2, and then print out the value in ASCII. + +Also keep in mind that the spaces are purely for readibility purposes. You +could just as easily write it as + +,[>+<-]>. + + +Try and figure out what this program does: + +,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >> + +This program takes two numbers for input, and multiplies them. + +The gist is it first reads in two inputs. Then it starts the outer loop, +conditioned on cell #1. Then it moves to cell #2, and starts the inner +loop conditioned on cell #2, incrementing cell #3. However, there comes a +problem: at the end of the inner loop, cell #2 is zero. To solve this problem, +we also increment cell #4, and then recopy cell #4 into cell #2. +``` + +And that's Brainfuck. Not that hard, eh? For fun, you can write your own +Brainfuck programs, or you can write a Brainfuck interpreter in another +language. The interpreter is fairly simple to implement, but if you're a +masochist, trying writing a Brainfuck interpreter... in Brainfuck. diff --git a/hu-hu/go.html.markdown b/hu-hu/go.html.markdown index 69849858..621ebdbf 100644 --- a/hu-hu/go.html.markdown +++ b/hu-hu/go.html.markdown @@ -38,7 +38,7 @@ import ( "strconv" // Stringek átalakítására szolgáló csomag ) -// Funkció deklarás, a main nevű funkció a program kezdőpontja. +// Funkció deklarálás, a main nevű funkció a program kezdőpontja. func main() { // Println kiírja a beadott paramétereket a standard kimenetre. // Ha más csomagot funkcióját akarjuk használni, akkor azt jelezni kell a diff --git a/php.html.markdown b/php.html.markdown index 1cc6d2c5..19f507ad 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -59,6 +59,9 @@ $float = 1.234; $float = 1.2e3; $float = 7E-10; +// Delete variable +unset($int1) + // Arithmetic $sum = 1 + 1; // 2 $difference = 2 - 1; // 1 @@ -136,6 +139,11 @@ echo $associative['One']; // prints 1 $array = ['One', 'Two', 'Three']; echo $array[0]; // => "One" +// Add an element to the end of an array +$array[] = 'Four'; + +// Remove element from array +unset($array[3]); /******************************** * Output @@ -177,7 +185,7 @@ echo $x; // => 2 echo $z; // => 0 // Dumps type and value of variable to stdout -var_dumb($z); // prints int(0) +var_dump($z); // prints int(0) // Prints variable to stdout in human-readable format print_r($array); // prints: Array ( [0] => One [1] => Two [2] => Three ) |