This exercise deals with Brainfuck.
The goal is to write a program (in the language of your choice) that takes a string as an input and outputs the corresponding Brainfuck program that prints that string to the screen.
What you will need:
- You will need a way to run Brainfuck programs. The easiest is to grab an interpreter from somewhere (here for example) or even better yet, write an interpreter yourself.
- A basic understanding of Brainfuck would help. The language is a bit weird but it's easy to get used to. Basically you need to understand the following code (taken from Wikipedia).
- Note that the output for a single string is never unique. There are literally infinite amounts of ways to print something on the screen. If participation is high enough, we could find a way to compare implementations.
The goal is to write a program (in the language of your choice) that takes a string as an input and outputs the corresponding Brainfuck program that prints that string to the screen.
What you will need:
- You will need a way to run Brainfuck programs. The easiest is to grab an interpreter from somewhere (here for example) or even better yet, write an interpreter yourself.
- A basic understanding of Brainfuck would help. The language is a bit weird but it's easy to get used to. Basically you need to understand the following code (taken from Wikipedia).
+++++ +++++ 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'
- Practicing some basic arithmetics in Bf wouldn't hurt much. Take a look at these exercises, doing these exercises is highly recommended.- Note that the output for a single string is never unique. There are literally infinite amounts of ways to print something on the screen. If participation is high enough, we could find a way to compare implementations.