Are your brain alright?
小海@夢想特急_夢城前
An introduction of brainf*ck.
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H'
> + . print 'e'
+++++ ++ . print 'l'
. print 'l'
+++ . print 'o'
> ++ . print ' '
<< +++++ +++++ +++++ . print 'W'
> . print 'o'
+++ . print 'r'
----- - . print 'l'
----- --- . print 'd'
> + . print '!'
> . print '\n'
An introduction of pointer, in C.
char space[30000];
int main() {
char *ptr = space;
*ptr = 'a';
}
如果有時間我們可以回來講
A runner, actually.
void run_code(char *code_start, char *code_end) {
char *space = (char *)calloc(max_size, sizeof(char));
char *ptr = space;
char *code = code_start;
while (code < code_end) {
switch (*code) {
case '>':
ptr++;
break;
case '<':
ptr--;
break;
case '+':
(*ptr)++;
break;
case '-':
(*ptr)--;
break;
case '.':
putchar(*ptr);
break;
case ',':
*ptr = getchar();
break;
case '[':
if (!(*ptr)) {
int lbraces = 0;
while ((*code) != ']' || lbraces != 1) {
if ((*code) == '[') lbraces++;
if ((*code) == ']') lbraces--;
code++;
}
}
break;
case ']':
if (*ptr) {
int rbraces = 0;
while ((*code) != '[' || rbraces != 1) {
if ((*code) == ']') rbraces++;
if ((*code) == '[') rbraces--;
code--;
}
}
break;
}
code++;
}
free(space);
space = ptr = NULL;
return;
}
TIOJ 1611