Hello world in brianfuck

in #brainfuck7 years ago (edited)

Brainfuck is a Turing Complete language that only has everything a programmer needs; C looks bloated compared to brainfuck. Here's some example code:

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

Beautiful, I know. But, this doesn't teach you how it works. That's what this post is going to change.

+ : 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 [ .

Above taken from https://learnxinyminutes.com/docs/brainfuck/

Ok, looks easy right? Here's how you write hello world:
+++++++ [ > ++++++++++ < - ] > ++ .

Actually this just prints H because writing hello world would take me 20 hours to type.

First, we increment cell 1 to 7.
Then we move to cell 2, enter the loop, and increment it 10 times.
We go back to cell 1 and decrement it once.
This happens 7 times.
When the loop is done, cell 1 is at 0, cell 2 is at 60. The loop is done, so we increment cell #2 by 2, making it 72.
the . then prints the current cell, which is 72, which is also the ascii value for H

Easy right?

Sort:  

Congratulations @anarch3! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You made your First Vote
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Eh, I'll write the hello:

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

Coin Marketplace

STEEM 0.22
TRX 0.20
JST 0.035
BTC 95967.22
ETH 3310.18
USDT 1.00
SBD 3.15