Submit | All submissions | Best solutions | Back to list |
BRAINF_K - Brainf_ck |
brainf*ck is the ungodly creation of Urban Mller, whose goal was apparently to create a Turing-complete language for which he could write the smallest compiler ever. http://en.wikipedia.org defines it as "a computer programming language designed to challenge and amuse programmers, and is not suitable for practical use. Its name has been variously euphemized, as in brainf*ck."
A brainf*ck program has an implicit byte pointer, called "the pointer", which is free to move around within an array of 32768 bytes, initially all set to zero. The pointer itself is initialized to point to the beginning of this array.
The brainf*ck programming language consists of seven commands, each of which is represented as a single character. Note: "Industry standard" brainf*ck actually has eight commands, but for the purposes of this problem one command was intentionally omitted.
COMMAND | OPERATION |
> | Increment the pointer. |
Incrementing a pointer value of 32767 | |
results in a pointer value of 0. | |
< | Decrement the pointer. |
Decrementing a pointer value of 0 | |
results in a pointer value of 32767. | |
+ | Increment the byte at the pointer. |
Incrementing the byte value 255 results | |
in the byte value 0. | |
- | Decrement the byte at the pointer. |
Decrementing the byte value 0 results | |
in the byte value 255. | |
. | Output the character whose ASCII |
value is the byte at the pointer | |
[ | Jump forward past the matching ] if the |
byte at the pointer is zero. | |
] | Jump backward to the matching [ |
unless the byte at the pointer is zero. |
For this problem, you will write a program that reads in, parses and executes a brainf*ck program.
Input
Input contains exactly one program. The program consists of one or more lines of brainf*ck commands. Your program should ignore any illegal characters (I.E. any character not in the set: <>+-.[]), If a percent sign (%) is encountered during parsing, the remainder of the line should be discarded. This constitutes a comment. The maximum number of commands in a brainf*ck program is 128000.
Output
Your program should output the output generated by the brainf*ck program. The only possible parsing error that can occur is if there is an unmatched [ or ] in the brainf*ck program. If your program encounters such an error, it should simply print "COMPILE ERROR" instead of executing the program. All brainf*ck programs will use no more than the specified 32768 bytes of memory.
Score
Score is the length of your source.
Example
Input: ++++++++[>+++++++++ % hello-world. <-]>.<+++++[>++++++<-]>-.+++++++.. +++.<++++++++[>>++++<<-]>>.<<++++[> ------<-]>.<++++[>++++++<-]>.+++. ------.--------.>+. Output: Hello World! Input: []] Output: COMPILE ERRORA super hard test case was removed.
Added by: | Bin Jin |
Date: | 2007-08-20 |
Time limit: | 1.735s |
Source limit: | 512B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | ACM/ICPC Greater New York Regional Contest 2005 |
hide comments
|
||||||
2012-09-13 14:44:49 Amit Kumar
my submission id is 7644212 please help me i spent whole day solving this problem... I m also getting WA after running(14) Also super hard test case does not give any output but it hangs up doing nothing Last edit: 2012-09-13 14:51:01 |
||||||
2012-06-28 14:27:03 (Tjandra Satria Gunawan)(曾毅昆)
when running a "super hard test case" code, it print the source code itself :O WOW! |
||||||
2012-06-01 12:31:54 :D
The same way some other problems can't be done using scripting languages because of the limit, this one is hard for C/C++. Still, 30 people got AC in C alone! There's no point in extending source limit that much in code golfing task. |
||||||
2012-06-01 12:20:52 Aditya Pande
plz check whats wrong in submission 7073094 it shows running(14) and then says WA. PLZ HELP... Last edit: 2012-06-01 13:23:41 |
||||||
2012-01-16 10:15:14 Paras Sharma
how would we know end of the input code. Last edit: 2012-01-16 10:16:48 |
||||||
2011-08-13 23:20:45 HWK
Finally found my error. Last edit: 2011-08-14 08:04:03 |
||||||
2011-07-17 03:55:50 dark passenger
When does the input terminates? Is the terminating ccondition EOF? |
||||||
2011-07-17 03:55:50 jayeshrao
@praveen.... the [ and ] specifies the jumps across memory locations...similar to a loop or a function call. Last edit: 2011-02-07 09:34:24 |
||||||
2011-07-17 03:55:50 praveen
hi friends can any one tell me whats the meaning of [ and ] |
||||||
2011-07-17 03:55:50 jean caffou
SPOJ will return Wrong Answer if you use read() and write() in C. Instead, use getchar() and putchar(). Also, there are no new lines in the output. |