changeset 7589:0127a61014cb

<Moon_> fetch http://pastebin.com/raw/yn9LVhJv
author HackBot
date Thu, 28 Apr 2016 22:28:16 +0000
parents 54457e160034
children 4d228c925379
files yn9LVhJv
diffstat 1 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yn9LVhJv	Thu Apr 28 22:28:16 2016 +0000
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+// initialize the tape with 30,000 zeroes
+unsigned long long int tape[30000] = {0};
+unsigned long long int registrar[3] = {0}; // R1, R2, and R3
+// set the pointer to point at the left-most cell of the tape
+unsigned long long int* ptr = tape;
+
+
+
+void interpret(char* input) {
+    char current_char;
+    size_t i;
+    size_t i2;
+    size_t i3;
+    size_t loop;
+    int i4;
+
+    for (i = 0; input[i] != 0; i++) {
+        current_char = input[i];
+        i4 = rand() % 11;
+        if (i4 == 0) {
+            ++ptr;
+        } else if (i4 == 1) {
+            --ptr;
+        } else if (i4 == 2) {
+            ++*ptr;
+        } else if (i4 == 3) {
+            --*ptr;
+        } else if (i4 == 4) {
+                putchar(*ptr);
+        } else if (i4 == 5) {
+
+            *ptr = getchar();
+
+        } else if (i4 == 6) {
+            continue;
+        } else if (i4 == 7 && *ptr) {
+            loop = 1;
+            while (loop > 0) {
+                current_char = input[--i];
+                if (current_char == '[') {
+                    loop--;
+                } else if (current_char == ']') {
+                    loop++;
+                }
+            }
+        } else if (i4 == 8) { // Jump forward n spaces
+
+            for (i2 = *ptr; i2 != 0; i2--) {
+                i++;
+                current_char = input[i];
+            }
+        } else if (i4 == 9) { // Jump backword n spaces
+            for (i2 = *ptr; i2 != 0; i2--) {
+                i--;
+                current_char = input[i];
+            }
+        }
+        // More commands to come, the CIOL specs are not done
+    }
+}
+
+
+int main( int argc, char *argv[] ) {
+
+    interpret(argv[1]);  // outputs input
+    return 0;
+}
\ No newline at end of file