annotate waDs9gmT @ 7602:c340aa00c2aa

<Moon_> ` mv wGAUV3ER Something.c
author HackBot
date Fri, 29 Apr 2016 00:11:57 +0000
parents 136a16f35a09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7595
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
1 #include <stdio.h>
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
2 #include <stdio.h>
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
3 #include <stdlib.h>
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
4 #include <string.h>
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
5
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
6
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
7 // initialize the tape with 30,000 zeroes
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
8 unsigned long long int tape[30000] = {0};
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
9 unsigned long long int registrar[3] = {0}; // R1, R2, and R3
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
10 // set the pointer to point at the left-most cell of the tape
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
11 unsigned long long int* ptr = tape;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
12
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
13
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
14
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
15 void interpret(char* input) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
16 char current_char;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
17 size_t i;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
18 size_t i2;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
19 size_t i3;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
20 size_t loop;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
21 int i4;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
22 time_t t;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
23 for (i = 0; input[i] != 0; i++) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
24 current_char = input[i];
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
25 srand((unsigned) time(&t));
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
26 i4 = rand() % 7;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
27 if (i4 == 0) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
28 ++ptr;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
29 } else if (i4 == 1) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
30 --ptr;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
31 } else if (i4 == 2) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
32 ++*ptr;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
33 } else if (i4 == 3) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
34 --*ptr;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
35 } else if (i4 == 4) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
36 putchar(*ptr);
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
37 } else if (i4 == 5) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
38
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
39 *ptr = getchar();
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
40
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
41 } else if (i4 == 6) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
42 continue;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
43 }
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
44 // More commands to come, the CIOL specs are not done
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
45 }
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
46 }
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
47
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
48
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
49 int main( int argc, char *argv[] ) {
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
50
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
51 interpret(argv[1]); // outputs input
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
52 return 0;
136a16f35a09 <Moon_> fetch http://pastebin.com/raw/waDs9gmT
HackBot
parents:
diff changeset
53 }