brainfuck

Printing a number in brainfuck?


I've searched for a while, but i couldn't find anything that could help me.

Let's say the first cell(or value, etc.) equals 165. How do i print "165"?

My idea was to cut the number into seperate pieces: 1,6 and 5. It would than be no problem to print them.

Note: I don't just want to print "165". I want to print the value the first cell has. No matter if it's 165, 255, 0, 1 or anything else.


Solution

  • use a famous modulo procedure ( http://esolangs.org/wiki/brainfuck_algorithms will help you)

    >+++++++++++[-<+++++++++++++++>] # initialize 165 at first cell
    >++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-
    <+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++
    <]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]