18
4
In any programming or scripting language x, write a program that takes a valid brainfuck sourcecode from stdin and output, to stdout, the sourcecode of a program, written in language x, that would output the exact same thing as the brainfuck program would do.
Your program must work for any valid brainfuck program, including the empty file.
Your score would be equal to the byte count of your sourcecode, plus the byte count of your output given the following input:
+++++ [-]
+++++ +++++ [
> +++++ ++
> ++ +++ ++++ +
> +++
<<< -
]
> ++ . H
> + . e
++ +++ ++. l
. l
+++ . o
> ++ . space
< +++++ +++ . w
----- --- . o
+++ . r
---- - - . l
----- --- . d
> + . exclamation mark
------lol; useless code :-)--------------------------[.............................................][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]<-<<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
For example, for an input of [-]
, the output of *p=0;
is much more favourable than while(*p) *p--;
If you happen to use non-ASCII characters, the byte count must be calculated using the UTF-8 encoding.
Lowest score wins. However, creative solutions that attempt to minimise the output shall be encouraged by upvotes.
11You might want to add a clause that the target language not also be brainfuck ;) – Josh – 2014-02-03T01:58:47.257
@Josh well, if someone managed to write a short brainfuck program that removes unnecessary useless codes, why not let them do it? – user12205 – 2014-02-03T11:11:39.320
2Well quite simply because the trivial solution of outputting the source unchanged is going to have a really low score anyway for brainfuck. I will be surprised if another language can beat that. – Tim Seguine – 2014-02-03T11:19:52.750
@Tim Seguine I could change the question, but would that be unfair to those who have already provided an answer? And if I change the question, I'm thinking about changing the score calculation, making it
byte count of source + (byte count of output)^2
, would that encourage people to focus more on simplifying the output? – user12205 – 2014-02-03T11:25:05.963Generally changing a question like that after it has already been answered is frowned upon. I was just pointing out a reason why I think Josh was right. It's good to post stuff like this in the sandbox first, so you can work out potential problems while being fair to everyone. – Tim Seguine – 2014-02-03T11:33:18.693
@Tim Seguine I'm hoping someone can come up with some clever way to minimise the output so as to win this. I mean, the given input essentially is just
print "Hello world!"
, if someone can reduce the output to, say, 200 bytes then even if their program is 300 bytes long they may still beat the current brainfuck solution – user12205 – 2014-02-03T11:37:00.077What about variants of brainfuck like pbrain? Technically not doing any translation at all is perfectly valid, yet at the same time there exists the opportunity to optimise. – Pharap – 2014-02-03T12:16:06.430
There's a pretty easy way to make it to less than 540+5 bytes (not in BF though) in a lot of languages, including PHP and JS. I'll investigate this further today, but given the example that you have to count as part of the bytecount, I can find a trivial solution. – FIQ – 2014-02-03T13:41:46.743
@FIQ looking forward to it :) – user12205 – 2014-02-03T14:43:49.200
@ace posted it, it's worse than my BF program currently, but that's because the script itself isn't very golfed down at all, the actual resulting script is minimal (for the test case anyways ;) ). – FIQ – 2014-02-03T18:49:25.963
@FIQ nice thinking, I like it – user12205 – 2014-02-03T18:55:33.523
Your scoring criterion is not precisely the source byte-count, so -- according to the blurb for the
code-golf
tag -- thecode-golf
tag should not be used, and thecode-challenge
tag should be used instead. – r.e.s. – 2014-02-04T02:07:03.007