BFK_AUTO - Automatic Brainf##k Code Generator (Shortening AI)


In this problem, you'll make an automatic Brainf**k code generator. Given a text file (input data), your program should output brainf**k code that if executed it will print the text file (exactly same with given input data). The text file containts printable ASCII character only: { '<line feed>'(ASCII(10)) , '<space>'(ASCII(32)) , ... , '~'(ASCII(126)) }. It's guaranteed that the filesize of text file is less than 1MB.

Input

Text file containing printable ASCII only with size<1MB.

Output

Brainf**k code that print that text file.

Score

Your score is: Sum of all BF code length in all test data

Example

Input:
Hello World!

Output:
++++++++++[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

Your Score (BF Code Length, valid command only):

111

 

Note: This is the first time I make my own judge, I've tested it hundred times with various test data, and so far no bug is found (found some but has been fixed). If you found a bug, you can send me info via PM or email, I'll fix that as soon as possible. Btw, here is the judge for this problem, maybe it'll be useful information for you. Good Luck and Have Fun :-D

See also: Another problem added by Tjandra Satria Gunawan


hide comments
meettaraviya: 2018-05-16 12:04:03

All testcases are passing except for two :(. My BF code is very efficient and takes much less number of cells than the bruteforce, even then the judge says I am using too many cells. Surprisingle bruteforce passes all test cases! I don't know what is wrong. Please help @Tjandra Satria Gunawan

(Tjandra Satria Gunawan)(曾毅昆): 2016-04-28 08:50:41

@linkret: BFF compiler in SPOJ use 32-bit unsigned for a cell, so because I made this problem for SPOJ, i should implement it in similar way. So changing it now will be too late because rejudging many solution with run under 22s time limit will be too difficult for SPOJ server, and not rejudging it seems unfair. So I leave this problem as it is.

linkret: 2016-04-11 22:27:25

In Brainfuck, aren't the cells supposed to be 8-bit? Why would you implement them as unsigned 32-bit ints?

Can you please change that in the judge, it wouldn't mess with the solutions that only use [0, 126] for representing the values anyway, and would make it work with usual BF techniques that are supposed to work.

I'd appreciate it alot :)

Last edit: 2016-04-11 22:53:56
VilimL: 2016-04-11 22:18:15

Why does the judge use unsigned int cells, while officially BF is supposed to use bytes?

Last edit: 2016-04-11 22:50:52
filipcve: 2016-04-07 20:49:06

When I test my code using ideone.com and a brainfuck interpreter it always gives me the expected answer, but SPOJ says my answer is wrong. Perhaps I misunderstood the format or something?

UPDATE
I guess my solution was compiler dependent, and I accidentally chose the wrong compiler here. It's working now.

Last edit: 2016-04-08 19:14:35
Mitch Schwartz: 2016-04-02 02:50:47

Judge code is here now: http://discuss.spoj.com/t/how-to-add-problem-into-spoj/693/34

(phpBB forum was migrated to Discourse.)

@testuser_124: Cells are implemented with unsigned int data type. Based on your description, you are trying to print a cell that is not in ASCII range, although for displaying as a char in the error message, the value is taken mod 256 (using %c in fprintf).

testuser_124: 2016-04-01 23:30:52

Judge says "Output of your BF code is not match with the test data: it should print '0'(ASCII(48)) but your BF code is printing '0'(ASCII(858993456))". How on earth can there be 858993456 characters in ASCII, and why is 858993456th the same as 48th?
(I've used fairly straightforward code which I plan to optimize further it works, I'm not sure whether I'm allowed to discuss the method here if, but I'm fairly certain it should work fine)
For what it's worth, I'm using Java and reading from System.in using BufferedReader#readLine until it returns null; I'm not quite sure whether that's the proper way, I see you mentioning files.

andrew hughes: 2015-04-05 03:57:24

Writing it in brainf**k itself threw a runtime error, do the inputs work with BF?

Flago: 2014-02-05 10:34:22

Great problem !

Could you give more information about the input, like, are chars random between allowed ones or is it some text from english (/other) language with predominant letters ?

<b><u>Ans</u>:</b> Thank you :) there are 22 test, some of the test use english language, some use random ASCII, some use other languange, and some have pattern which could be compressed!

<b><u>Ans</u>:</b> Thx, hmmm Im kinda new at this... Is it allowed to dig information from the test cases by something like this :
<b>cin>>firstChar;
while(firstChar=='A');</b>
To get either TLE if first char is A, or WA if it is not ?

<b><u>Ans2</u>:</b> Yes, it's allowed :) but you'll need tousand/million number of submissions to get entire text :P

<b><u>Ans2</u>:</b> Ye ofc it will, but... I could do it like this :
while(cin>>getChar){
if(getChar=='E')countE++;
else count++;
}
while(countE/count>0.1); //Testing some others values than 0.1

Wouldn't take that long to approx proportion of some letters like this, to determine either if the case is random, or if it is english/other language :D Still, would be boring and take quite some time... 'll do this later maybe :p

Last edit: 2014-02-10 15:59:19
(Tjandra Satria Gunawan)(曾毅昆): 2013-06-04 23:29:50

Experiment with MasterJudge done! now you can see more detailed result from MasterJudge: e.g. user's running time, user's memory usage, etc.
and @Francky: Maybe I know why your MasterJudge led to internal error (because I did that mistake too), I'll send you a PM with detailed explanation.
--ans--> No, I didn't use .c extension, but .c++, I'll try again with .cpp. ??? (when I'll find some time).
Edit(Tjandra): Or you can change the include <cstdio> to <stdio.h> (and other C++ syntax convert to C), and use *.c exstention. This problem's MasterJudge is written in C language.

Last edit: 2013-06-05 18:22:02

Added by:Tjandra Satria Gunawan
Date:2013-05-25
Time limit:22s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:This problem is purely came from my own idea \(^_^)/