#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// initialize the tape with 30,000 zeroes
unsigned char tape[30000] = {0};
// set the pointer to point at the left-most cell of the tape
unsigned char* ptr = tape;
void interpret(char* input) {
char current_char;
size_t i;
size_t loop;
for (i = 0; input[i] != 0; i++) {
current_char = input[i];
if (current_char == '>') {
++ptr;
} else if (current_char == '<') {
--ptr;
} else if (current_char == '+') {
++*ptr;
} else if (current_char == '-') {
--*ptr;
} else if (current_char == '.' ) {
putchar(*ptr);
} else if (current_char == ',') {
*ptr = getchar();
} else if (current_char == '[') {
continue;
} else if (current_char == ']' && *ptr) {
loop = 1;
while (loop > 0) {
current_char = input[--i];
if (current_char == '[') {
loop--;
} else if (current_char == ']') {
loop++;
}
}
}
}
}
int main() {
interpret("-------------------------------------------------------------------[>[-]<[-]]>[>--------------------------------------------------------[>[-]<[-]]>[>-------------------------------------------------------[>[-]<[-]]>[>------------------------------------------------------[>[-]<[-]]>[>---------------------------------------------------[>[-]<[-]]>[>---------------------------------[>[-]<[-]]>[>>----[---->+<]>++.++++++++.++++++++++.>-[----->+<]>.+[--->++<]>+++.>-[--->+<]>-.[---->+++++<]>-.[-->+<]>---.[--->++<]>---.++[->+++<]>.+[-->+<]>+.[--->++<]>---.++[->+++<]>.+++.[--->+<]>----.[-->+<]>-----.[->++<]>+.-[---->+++<]>.--------.>-[--->+<]>.-[----->+<]>-.++++++++.--[----->+++<]>.+++.[--->+<]>-.-[-->+<]>---.++[--->+++++<]>.++++++++++++++.+++[->+++++<]>.[----->+<]>++.>-[----->+<]>.---[->++<]>-.++++++.[--->+<]>+++.+++.[-]]]]]]]"); // outputs input
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKLy8gaW5pdGlhbGl6ZSB0aGUgdGFwZSB3aXRoIDMwLDAwMCB6ZXJvZXMKdW5zaWduZWQgY2hhciB0YXBlWzMwMDAwXSA9IHswfTsKIAovLyBzZXQgdGhlIHBvaW50ZXIgdG8gcG9pbnQgYXQgdGhlIGxlZnQtbW9zdCBjZWxsIG9mIHRoZSB0YXBlCnVuc2lnbmVkIGNoYXIqIHB0ciA9IHRhcGU7CgoKdm9pZCBpbnRlcnByZXQoY2hhciogaW5wdXQpIHsKICAgIGNoYXIgY3VycmVudF9jaGFyOwogICAgc2l6ZV90IGk7CiAgICBzaXplX3QgbG9vcDsKCiAgICBmb3IgKGkgPSAwOyBpbnB1dFtpXSAhPSAwOyBpKyspIHsKICAgICAgICBjdXJyZW50X2NoYXIgPSBpbnB1dFtpXTsKICAgICAgICBpZiAoY3VycmVudF9jaGFyID09ICc+JykgewogICAgICAgICAgICArK3B0cjsKICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRfY2hhciA9PSAnPCcpIHsKICAgICAgICAgICAgLS1wdHI7CiAgICAgICAgfSBlbHNlIGlmIChjdXJyZW50X2NoYXIgPT0gJysnKSB7CiAgICAgICAgICAgICsrKnB0cjsKICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRfY2hhciA9PSAnLScpIHsKICAgICAgICAgICAgLS0qcHRyOwogICAgICAgIH0gZWxzZSBpZiAoY3VycmVudF9jaGFyID09ICcuJyApIHsKICAgICAgICAgICAgcHV0Y2hhcigqcHRyKTsKICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRfY2hhciA9PSAnLCcpIHsKICAgICAgICAgICAgKnB0ciA9IGdldGNoYXIoKTsKICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRfY2hhciA9PSAnWycpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgfSBlbHNlIGlmIChjdXJyZW50X2NoYXIgPT0gJ10nICYmICpwdHIpIHsKICAgICAgICAgICAgbG9vcCA9IDE7CiAgICAgICAgICAgIHdoaWxlIChsb29wID4gMCkgewogICAgICAgICAgICAgICAgY3VycmVudF9jaGFyID0gaW5wdXRbLS1pXTsKICAgICAgICAgICAgICAgI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