If you came to this contest, it’s because you like programming. And, if you like programming, you must love programming languages. You probably agree with me that it’s a pity that we don’t have time to learn, to experiment and to play with all those fantastic languages around us. We know: “so many languages, so little time”.
Recently, I came across Braincrash (BC), reputedly the simplest language of them all: it runs on a vocabulary of only two symbols: the exclamation mark (’!’) and the underscore (’_’) and it is Turing complete. The language has no syntax, meaning that any string formed by only underscores and exclamation marks is a valid BC program, syntactically speaking. The semantics is defined in terms of another beautiful language, Brainfuck (BF). BF uses eight symbols, +-><.,, (plus sign, minus sign, greater than, less than, dot, comma, open square bracket, close square bracket), which makes it a language three orders of magnitude more complicated than BC.
The procedure for translating from BC to BF is rather straightforward: just align the BC program with an infinite repetition of the string “+-><.,”, and pick those characters that are aligned with the exclamation mark. Here’s an example:
This gives the following BF program:
which any BF fan easily recognizes as the cat program, that copies from the standard input to the standard output.
Your task is to write a program that translates a BF program into the shortest equivalent BC program. In the BF program, any char which is not in the set +-><., is considered a comment and should be ignored by the translation.
The input is a BF program, with an undetermined number of lines. The BF program is not empty, even after removing all the comment characters.
The output file contains a single line with the BC program.
The maximum size of the input (including newline characters) is 13,000 characters.
MIUP'2012, 20 de Outubro, DCC/FCUP
This document was translated from LATEX by HEVEA.