This is inspired by the Brainf*** to tinyBF converter challenge.
Brainf**k (which will be henceforth referred to as BF) is a well-known estoric programming language, so I won't go over it too much here.
Nameless language is a binary-looking version of BF. See the linked page for more info.
Your challenge is to implement a golfed Nameless-to-BF converter. It should implement all of the commands except for 1100 (which isn't really possible to implement in BF) and 1010 (that isn't really possible, either). Any characters other than 1's and 0's should be ignored because they can be used for comments (after all, you wouldn't want an unreadable program, right? ;).
Here's a simple table of a Nameless -> BF mapping:
0000 -> >
0001 -> <
0010 -> +
0011 -> -
0100 -> .
0101 -> ,
0110 -> [
0111 -> ]
1011 -> [-]
1000 -> adds the base 10 value of the next command to the current memory cell (see below)
1001 -> subtracts the base 10 value of the next command from the current memory cell (see below)
NOTE: I accidentally flipped <
and >
. Thanks to @IlmariKaronen for pointing that out.
For 1000 and 1001, you can directly implement it in the translator. For instance, this:
1000 0010
could be written as:
++
The translator determined the value of the next command in advance and wrote it out.
Invalid sequences (e.g. 1111) and the presence of 1000/1001 at the end of the program are undefined; you don't have to handle them.
MAY THE GOLFING BEGIN!!!
+
in BF increments the current cell by 1 (so if the current cell has a value of 2,+
would make it 3.)1000 0100
does become++++++++
and1001 0100
becomes---------
. I'm also assuming1000
/1001
at the end of a line is also undefined. \$\endgroup\$0100
is 4, by the way, so1000 0100
is++++
. \$\endgroup\$1000 0100
becomes++++.
. \$\endgroup\$