From 4615f188ce7a3b56d3d612e9e2554cfb63b764d4 Mon Sep 17 00:00:00 2001 From: Radovan Kofira Date: Tue, 5 Jan 2021 12:05:26 +0100 Subject: [PATCH] a --- skuska/program.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ skuska/readme.MD | 2 ++ 2 files changed, 52 insertions(+) create mode 100644 skuska/program.c create mode 100644 skuska/readme.MD diff --git a/skuska/program.c b/skuska/program.c new file mode 100644 index 0000000..a0c08c0 --- /dev/null +++ b/skuska/program.c @@ -0,0 +1,50 @@ +#include +#include +#include + +// 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; +} \ No newline at end of file diff --git a/skuska/readme.MD b/skuska/readme.MD new file mode 100644 index 0000000..db20947 --- /dev/null +++ b/skuska/readme.MD @@ -0,0 +1,2 @@ +Riesenie inspirovane https://gist.github.com/maxcountryman/1699708 +