Take a look at the 'Hello World' Bf program from Wikipedia:
Then the pointer goes through these cells, modifying their values to reach the desired ASCII value and prints it to the screen with '.'
The exercise consists of writing a program that takes a string as an input and outputs the shortest brainfuck program printing the string to the screen.
Hint: Make sure you understand correctly how the above Hello World program works, so you get a good grasp of the exercise. You'll probably have to set up some initial state (70/100/30/10 seems like a good idea, unless you think of something better). The rest consists of deciding which cell to modify next.
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H'
> + . print 'e'
+++++ ++ . print 'l'
. print 'l'
+++ . print 'o'
> ++ . print ' '
<< +++++ +++++ +++++ . print 'W'
> . print 'o'
+++ . print 'r'
----- - . print 'l'
----- --- . print 'd'
> + . print '!'
> . print '\n'
The way it works is simple: the firtst loops sets 4 cells to the values 70/100/30/10. Then the pointer goes through these cells, modifying their values to reach the desired ASCII value and prints it to the screen with '.'
The exercise consists of writing a program that takes a string as an input and outputs the shortest brainfuck program printing the string to the screen.
Hint: Make sure you understand correctly how the above Hello World program works, so you get a good grasp of the exercise. You'll probably have to set up some initial state (70/100/30/10 seems like a good idea, unless you think of something better). The rest consists of deciding which cell to modify next.