Submit | All submissions | Best solutions | Back to list |
BFBINADD - The Brain-Folk Computer |
The inhabitants of Brainlandia love rabbits. Every household keeps track of the number of rabbits it owns with great diligence. There are, in fact, exactly 30,000 houses in Brainlandia, all lying in a perfectly straight line on the northern bank of the Tarpit River. The famous Brainlandian magician Corrado likes to go from door to door making rabbits appear out of his hat, thus increasing the number of rabbits in that household. He is only able to make rabbits appear, not disappear, and he can only travel east, because when he tries to travel west the wind catches his hat the wrong way and it loses its magical power.
On the other side of the river lies the strange town of Folklandia. Unlike their neighbors to the north, Folklandians hate rabbits. Employees of the rabbit pest control company Urban Exterminators go from door to door trying to eliminate as many rabbits as they can. They can only travel west because of faulty compasses installed in their vehicles. Naturally they tend to keep away from Brainlandians, for fear of rabbit infestations.
Unfortunately, neither the Brainlandians nor the Folklandians are very good at mathematics. In particular, they have quite a hard time determining how many rabbits they'll have after a visit from Corrado or from Urban Exterminators, as the case may be. If only they had a computer that could tell them the answer...
A traveling key manufacturer named Louis has recently visited the two towns and got to thinking that, with a little cooperation, the towns themselves could act as powerful computers! First of all, Corrado could travel inside the vehicles driven by Urban Exterminators, allowing him to escape the wind and travel west. Additionally, with his magical powers he could fix the compasses and allow the vehicles to travel east. Finally, Louis has invented a very concise programming language to instruct the magician-exterminator team where to go and when to increase or decrease the number of rabbits.
The inhabitants of the two towns are skeptical that Louis's proposal would allow them to compute anything useful. It has been decided that the true test will be whether Louis can provide them with a program to help them keep track of their rabbits. They are more concerned with addition than subtraction, since they are familiar with two's complement. Also, they prefer doing everything in binary because that way they only have to remember two symbols.
Louis has just had a tall glass of freshly squeezed orange juice, and he now feels ready to write the program and prove that his language can do everything he says it can. As all programs must be written on punch cards and those cards are very expensive to make, Louis would like to write as short a program as possible.
Note: You can use any programming language you want, as long as it is brainf**k.
Input
The first line contains an integer T (1 ≤ T ≤ 1000). Then follow T lines, each containing integers A and B (0 ≤ A,B ≤ 2^100) in binary, separated by a single space. Each line, including the last, is terminated by a single newline (linefeed) character, which has ASCII value 10.
Output
T lines containing the value of A+B in binary.
Score
The score is the number of brainf**k commands in your program. All other characters are ignored.
Example
Input:
5 0 0 0 101010 101010 0 101010 101010 1011011101111011111 1011011011101
Output:
0 101010 101010 1010100 1011101001010111100
Additional Info
There are two randomly generated data sets, one with T=1000 and the other with T=500. A and B are generated independently, and the average number of bits in either is about 50.
My solution at the time of publication has 232 bytes and runs in 0.25s with 1.9M memory footprint. I also have a 230-byte solution for bff 1.0.5 that would run in about 7.7s with a somewhat larger memory footprint.
I have made the C++ source for my test case judge available (probably of interest only to problem setters). It is a minor variation on the standard "Score is source length" judge.
Update: Reduced source to 201 in bff 1.0.3.1 and 191 in bff 1.0.5 as of 2014-11-07.
Added by: | Mitch Schwartz |
Date: | 2013-06-01 |
Time limit: | 20s |
Source limit: | 5000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | BF |
Resource: | Own problem |
hide comments
|
|||||
2013-07-11 16:00:38 (Tjandra Satria Gunawan)(曾毅昆)
@Mitch Schwartz: from comment below You said: "And actually BFMUL and BFDIV were designed to encourage submissions to a problem that I've written but haven't gotten around to solving yet!" I guess you're trying to make BFEXPO (modular exponentiation) or BFSQRT (square root) right? In my opinion those are very good task ;-) Ans(Mitch): I'll fill you in on the details by email. :) Last edit: 2013-07-11 16:17:49 |
|||||
2013-06-20 16:10:15 Mostafa 36a2
Maybe a complete Logical operation calculator AND OR XOR NOT NAND NOR BUFFER/yes XNOR maybe you can add shifting or roling Maybe something about BCD Gray to Binary converter ..... Oh Man ... what about interleave or select (Those in Intercal you know) those are some ideas It's up to you now Best Regards :) Ans(Mitch): Maybe just include buffer and ditch all the other operations :p. Those are interesting ideas, but I'm not sure this problem could be considered an easier version of that any more than this is an easier version of BFMUL; in fact, this problem started out as a way to encourage BFMUL submissions, and originally there wasn't a golf goal but I thought that golfing made it more interesting. (And actually BFMUL and BFDIV were designed to encourage submissions to a problem that I've written but haven't gotten around to solving yet! :D) (Mostafa) I think You may wait until spojers finish the exams (in fact I have an exam tomorrow O_O ) Better Make a Harder Version Of BFMUL with strict time to get an efficient code :) (Mitch) I don't know, I think it's tricky enough to get AC in BFMUL with the current time limit; maybe for the follow-up problems such inefficiencies would accumulate to the point of being unsolvable without faster BFMUL, but it's not really my intention to reject correct but somewhat slower solutions. Last edit: 2013-06-24 02:56:28 |
|||||
2013-06-20 14:16:16 Mostafa 36a2
If You really want to promote this I think we should report all the trash here in tutorial section ! isn't it better to delete them by admins ? btw this problem will be Useful When it attached with a hard version ... Regerds :) Ans(Mitch): Thanks for the feedback, it's on my todo list to review the tutorial section and hide any clearly broken or otherwise unacceptable problems (as EB member I can do this), you've made a good point. Regarding a more difficult version: What ideas do you have? Maybe put in classical with same test data and strict source/time limits? Last edit: 2013-06-20 15:03:45 |
|||||
2013-06-20 07:20:53 Mostafa 36a2
Hello Mitch .. Are You going to move this problem to challenge section or it'll stay here? Ans(Mitch): I would like to leave this problem in tutorial, but maybe it can be added to SHORTEN, I'll ask Jander what his opinion is on that. There are already several BF code golf problems in challenge section, and I would like to encourage more variety. I have some NP-hard types of problems in mind to publish, when I can find the time. Also, if I publish a (BF or non-BF) code golf problem in challenge section, I'd like it to be a little more complex than this one. Also, I want to promote the idea that tutorial section is for good easier problems, not for trash problems! Last edit: 2013-06-20 11:23:34 |