9
\$\begingroup\$

We have a Brainf*** to TinyBF converter, but not the other way around, so here's one.

Rules:

  • Your interpreter must take a valid TinyBF program, on one line, and it must output the corresponding BrainF*** program, on one line, with optional trailing whitespace/newline. No leading whitespace is allowed
  • The input may or may not contain characters that are not any of the four TinyBF characters. If so, you must print all of these characters in the same spots.
  • An answer will be accepted on April 1st (not joking), based on some obscure criteria I will use (jk ;) I will accept the shortest program that does not cheat by the following rules)
  • No 0-byte or 1-byte solutions, because it ruins the fun if you make (or there is) a programming language just for this purpose)

Test Cases


Input 1: +++++>+++++=>=|>>+=>>+|=>|>+=>+| (Computes 5 (byte 1) + 5 (byte 2) = 10 (byte 3))
Output 1: +++++>+++++<[>>+<<-]>[>+<-]

Input 2: +++>++++Hi+++:P+=>=|>|>+>+=>>&&+|=>>|=>>=+!!>>=+|>>>+| (Computes 3 (byte 1) * 8 (byte 2) = 24 (byte 3)) Output 2: +++>++++Hi+++:P+<[>[>+>+<<&&-]>>[<<+!!>>-]<<<-]

\$\endgroup\$
  • \$\begingroup\$ Will there ever be I/O commands? \$\endgroup\$ – lirtosiast Feb 15 '16 at 22:05
  • \$\begingroup\$ No, because TinyBF doesn't have IO commands. \$\endgroup\$ – HyperNeutrino Feb 16 '16 at 2:27
  • \$\begingroup\$ That's incorrect; == is brainfuck's .. \$\endgroup\$ – Dennis Feb 13 '18 at 23:16
1
\$\begingroup\$

Python 2, 106 bytes

a=0
r=''
for c in input():a=[a,~a][c=='='];r+={'+':'+-','>':'><','|':'[]'}.get(c,c)[a%-2]*(c!='=')
print r

Implements the TinyBF specification as found here. Try it online. Improvements were made using techniques from @Dica's answer. Requires quoted string input.

\$\endgroup\$
  • \$\begingroup\$ This works for all of my test cases! Good job. \$\endgroup\$ – HyperNeutrino Feb 16 '16 at 14:43
  • \$\begingroup\$ You can save 5 bytes with r+=b.get(c,c+c)[a]*(c!='='). You can also make the for loop one line to save 3 more. You can inline the dict to save 4 more. Inlining input() is another 4. \$\endgroup\$ – Morgan Thrapp Feb 16 '16 at 14:44
  • \$\begingroup\$ Also, you need to either use raw_input or switch to Python 3 and take the byte penalty for print. Right now I get SyntaxError: invalid syntax. \$\endgroup\$ – Morgan Thrapp Feb 16 '16 at 14:50
  • \$\begingroup\$ @Mergo I based my answer on yours but I guess it's okay because the modifications are heavy, let me know if you want me to remove it \$\endgroup\$ – Dica Feb 16 '16 at 17:14
  • \$\begingroup\$ @MorganThrapp The input is quoted, so it works for 2. Taking quoted string input is allowed per a meta post that I can't find right now because I'm on mobile. \$\endgroup\$ – Mego Feb 16 '16 at 17:36
2
\$\begingroup\$

Python 3, 97 bytes

This script is based on @Mego's answer

a=0
for c in input():a-=c=='=';print({'+':'+-','>':'><','|':'[]'}.get(c,c)[a%-2]*(c!='='),end='')
\$\endgroup\$
  • 3
    \$\begingroup\$ I think this is too similar to Mego's answer and should have been suggested as an optimization in a comment. \$\endgroup\$ – mbomb007 Feb 26 '16 at 3:31
  • \$\begingroup\$ Although this is shorter, I accepted Mego's answer because your answer is too similar to Mego's an seems like an optimization rather than a distinct answer. \$\endgroup\$ – HyperNeutrino Jan 19 '17 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.