From 14da3497ed0d4c788fd90094792357fd8783a40b Mon Sep 17 00:00:00 2001 From: Alex Hirsch Date: Mon, 18 Mar 2019 13:50:36 +0100 Subject: [PATCH] Add student example inputs --- examples/agecontrol/agecontrol.mc | 28 +++ examples/agecontrol/agecontrol.stdin.txt | 1 + examples/agecontrol/agecontrol.stdout.txt | 2 + examples/dijkstra/dijkstra.mc | 179 ++++++++++++++++++ examples/dijkstra/dijkstra.stdin.txt | 12 ++ examples/dijkstra/dijkstra.stdout.txt | 16 ++ examples/draw/draw.mc | 45 +++++ examples/draw/draw.stdin.txt | 0 examples/draw/draw.stdout.txt | 52 +++++ examples/euclid/euclid.mc | 45 +++++ examples/euclid/euclid.stdin.txt | 2 + examples/euclid/euclid.stdout.txt | 4 + .../euclidean_division/euclidean_division.mc | 44 +++++ .../euclidean_division.stdin.txt | 2 + .../euclidean_division.stdout.txt | 3 + examples/factorial/factorial.mc | 29 +++ examples/factorial/factorial.stdin.txt | 1 + examples/factorial/factorial.stdout.txt | 2 + examples/flw/flw.mc | 98 ++++++++++ examples/flw/flw.stdin.txt | 2 + examples/flw/flw.stdout.txt | 21 ++ examples/gcd/gcd.mc | 43 +++++ examples/gcd/gcd.stdin.txt | 2 + examples/gcd/gcd.stdout.txt | 3 + examples/intToBin/intToBin.mc | 61 ++++++ examples/intToBin/intToBin.stdin.txt | 3 + examples/intToBin/intToBin.stdout.txt | 4 + examples/is_square/is_square.mc | 29 +++ examples/is_square/is_square.stdin.txt | 1 + examples/is_square/is_square.stdout.txt | 2 + examples/nim/nim.mc | 144 ++++++++++++++ examples/nim/nim.stdin.txt | 6 + examples/nim/nim.stdout.txt | 28 +++ examples/nonsense/nonsense.mc | 61 ++++++ examples/nonsense/nonsense.stdin.txt | 0 examples/nonsense/nonsense.stdout.txt | 6 + examples/palindrome/palindrome.mc | 45 +++++ examples/palindrome/palindrome.stdin.txt | 1 + examples/palindrome/palindrome.stdout.txt | 2 + examples/slowsort/slowsort.mc | 151 +++++++++++++++ examples/slowsort/slowsort.stdin.txt | 11 ++ examples/slowsort/slowsort.stdout.txt | 18 ++ .../supersyntaxchecker2000.mc | 34 ++++ .../supersyntaxchecker2000.stdin.txt | 1 + .../supersyntaxchecker2000.stdout.txt | 1 + 45 files changed, 1245 insertions(+) create mode 100644 examples/agecontrol/agecontrol.mc create mode 100644 examples/agecontrol/agecontrol.stdin.txt create mode 100644 examples/agecontrol/agecontrol.stdout.txt create mode 100644 examples/dijkstra/dijkstra.mc create mode 100644 examples/dijkstra/dijkstra.stdin.txt create mode 100644 examples/dijkstra/dijkstra.stdout.txt create mode 100644 examples/draw/draw.mc create mode 100644 examples/draw/draw.stdin.txt create mode 100644 examples/draw/draw.stdout.txt create mode 100644 examples/euclid/euclid.mc create mode 100644 examples/euclid/euclid.stdin.txt create mode 100644 examples/euclid/euclid.stdout.txt create mode 100644 examples/euclidean_division/euclidean_division.mc create mode 100644 examples/euclidean_division/euclidean_division.stdin.txt create mode 100644 examples/euclidean_division/euclidean_division.stdout.txt create mode 100644 examples/factorial/factorial.mc create mode 100644 examples/factorial/factorial.stdin.txt create mode 100644 examples/factorial/factorial.stdout.txt create mode 100644 examples/flw/flw.mc create mode 100644 examples/flw/flw.stdin.txt create mode 100644 examples/flw/flw.stdout.txt create mode 100644 examples/gcd/gcd.mc create mode 100644 examples/gcd/gcd.stdin.txt create mode 100644 examples/gcd/gcd.stdout.txt create mode 100644 examples/intToBin/intToBin.mc create mode 100644 examples/intToBin/intToBin.stdin.txt create mode 100644 examples/intToBin/intToBin.stdout.txt create mode 100644 examples/is_square/is_square.mc create mode 100644 examples/is_square/is_square.stdin.txt create mode 100644 examples/is_square/is_square.stdout.txt create mode 100644 examples/nim/nim.mc create mode 100644 examples/nim/nim.stdin.txt create mode 100644 examples/nim/nim.stdout.txt create mode 100644 examples/nonsense/nonsense.mc create mode 100644 examples/nonsense/nonsense.stdin.txt create mode 100644 examples/nonsense/nonsense.stdout.txt create mode 100644 examples/palindrome/palindrome.mc create mode 100644 examples/palindrome/palindrome.stdin.txt create mode 100644 examples/palindrome/palindrome.stdout.txt create mode 100644 examples/slowsort/slowsort.mc create mode 100644 examples/slowsort/slowsort.stdin.txt create mode 100644 examples/slowsort/slowsort.stdout.txt create mode 100644 examples/supersyntaxchecker2000/supersyntaxchecker2000.mc create mode 100644 examples/supersyntaxchecker2000/supersyntaxchecker2000.stdin.txt create mode 100644 examples/supersyntaxchecker2000/supersyntaxchecker2000.stdout.txt diff --git a/examples/agecontrol/agecontrol.mc b/examples/agecontrol/agecontrol.mc new file mode 100644 index 0000000..4d35238 --- /dev/null +++ b/examples/agecontrol/agecontrol.mc @@ -0,0 +1,28 @@ +bool ageforalco(int n) +{ + if (n < 21) { + return false; + } + + return true; +} + +int main() +{ + print("Enter you age: "); + + int age; + age = read_int(); + print_nl(); + + bool result; + result = ageforalco(age); + + if (!result) { + print("You Can't drink ):"); + } + else { + print("You Can Drink!"); + } + print_nl(); +} diff --git a/examples/agecontrol/agecontrol.stdin.txt b/examples/agecontrol/agecontrol.stdin.txt new file mode 100644 index 0000000..410b14d --- /dev/null +++ b/examples/agecontrol/agecontrol.stdin.txt @@ -0,0 +1 @@ +25 \ No newline at end of file diff --git a/examples/agecontrol/agecontrol.stdout.txt b/examples/agecontrol/agecontrol.stdout.txt new file mode 100644 index 0000000..2c52e8d --- /dev/null +++ b/examples/agecontrol/agecontrol.stdout.txt @@ -0,0 +1,2 @@ +Enter you age: +You Can Drink! diff --git a/examples/dijkstra/dijkstra.mc b/examples/dijkstra/dijkstra.mc new file mode 100644 index 0000000..3389c76 --- /dev/null +++ b/examples/dijkstra/dijkstra.mc @@ -0,0 +1,179 @@ + +void dijkstra(int[15] path_cost) +{ + int[15] calc_cost; + int i; + int j; + i = 0; + + while (i < 4) + { + j = 0; + while (j < 4) + { + if (path_cost[i * 4 + j] == 0) + calc_cost[i * 4 + j] = 9999; + else + calc_cost[i * 4 + j] = path_cost[i * 4 + j]; + + j = j + 1; + } + i = i + 1; + } + + int[4] distance; + bool[4] visited; + + int node_count; + int next_node; + node_count = 0; + + while (node_count < 4) + { + distance[node_count] = calc_cost[node_count]; + + if (node_count == 0) + visited[node_count] = true; + else + visited[node_count] = false; + + node_count = node_count + 1; + } + + node_count = 1; + + while (node_count < 4) + { + int min_distance; + int traversel_count; + + min_distance = 9999; + traversel_count = 0; + + while (traversel_count < 4) + { + if (!visited[traversel_count] && + distance[traversel_count] < min_distance) + { + min_distance = distance[traversel_count]; + next_node = traversel_count; + } + traversel_count = traversel_count + 1; + } + + visited[next_node] = true; + traversel_count = 0; + + while (traversel_count < 4) + { + if (!visited[traversel_count]) + { + if (distance[traversel_count] > + calc_cost[next_node * 4 + traversel_count] + min_distance) + { + distance[traversel_count] = + calc_cost[next_node * 4 + traversel_count] + min_distance; + } + } + traversel_count = traversel_count + 1; + } + node_count = node_count + 1; + } + + int print_counter; + print_counter = 1; + while (print_counter < 4) + { + print("Distance to node "); + print_int(print_counter); + print(" = "); + print_int(distance[print_counter]); + print_nl(); + + print_counter = print_counter + 1; + } +} + +int main() +{ + int[15] path_cost; + int input_counter; + int node_counter; + input_counter = 1; + node_counter = 1; + path_cost[0] = 0; + + print("Enter the path costs ('0' = no path)"); + print_nl(); + + while (input_counter < 15) + { + if (input_counter < 4) + { + print("Enter path cost from 0 -> "); + print_int(node_counter); + print(":"); + print_nl(); + path_cost[input_counter] = read_int(); + } + + if (input_counter >= 4 && input_counter < 8) + { + if (input_counter != 5) + { + print("Enter path cost from 1 -> "); + print_int(node_counter); + print(":"); + print_nl(); + path_cost[input_counter] = read_int(); + } + else + { + path_cost[input_counter] = 0; + } + } + + if (input_counter >= 8 && input_counter < 12) + { + if (input_counter != 10) + { + print("Enter path cost from 2 -> "); + print_int(node_counter); + print(":"); + print_nl(); + path_cost[input_counter] = read_int(); + } + else + { + path_cost[input_counter] = 0; + } + } + + if (input_counter >= 12) + { + if (input_counter != 15) + { + print("Enter path cost from 3 -> "); + print_int(node_counter); + print(":"); + print_nl(); + path_cost[input_counter] = read_int(); + } + else + { + path_cost[input_counter] = 0; + } + } + + if (node_counter >= 3) + node_counter = 0; + else + node_counter = node_counter + 1; + + input_counter = input_counter + 1; + } + + dijkstra(path_cost); + + return 0; +} \ No newline at end of file diff --git a/examples/dijkstra/dijkstra.stdin.txt b/examples/dijkstra/dijkstra.stdin.txt new file mode 100644 index 0000000..d1aaebf --- /dev/null +++ b/examples/dijkstra/dijkstra.stdin.txt @@ -0,0 +1,12 @@ +10 +30 +70 +0 +10 +40 +0 +0 +10 +0 +0 +0 diff --git a/examples/dijkstra/dijkstra.stdout.txt b/examples/dijkstra/dijkstra.stdout.txt new file mode 100644 index 0000000..48a0308 --- /dev/null +++ b/examples/dijkstra/dijkstra.stdout.txt @@ -0,0 +1,16 @@ +Enter the path costs ('0' = no path) +Enter path cost from 0 -> 1: +Enter path cost from 0 -> 2: +Enter path cost from 0 -> 3: +Enter path cost from 1 -> 0: +Enter path cost from 1 -> 2: +Enter path cost from 1 -> 3: +Enter path cost from 2 -> 0: +Enter path cost from 2 -> 1: +Enter path cost from 2 -> 3: +Enter path cost from 3 -> 0: +Enter path cost from 3 -> 1: +Enter path cost from 3 -> 2: +Distance to node 1 = 10 +Distance to node 2 = 20 +Distance to node 3 = 30 diff --git a/examples/draw/draw.mc b/examples/draw/draw.mc new file mode 100644 index 0000000..3bdc96a --- /dev/null +++ b/examples/draw/draw.mc @@ -0,0 +1,45 @@ +void drawrect(int w, int h) { + int i; + int j; + + i = 0; + while(i < w) { + print("x"); + i = i + 1; + } + + print_nl(); + + i = 2; + while(i < h) { + print("x"); + + j = 2; + while(j < w) { + print(" "); + j = j + 1; + } + + print("x"); + print_nl(); + i = i + 1; + } + + i = 0; + while(i < w) { + print("x"); + i = i + 1; + } + + print_nl(); +} + +int main() { + drawrect(10, 15); + drawrect(3, 5); + drawrect(50, 20); + drawrect(10, 10); + drawrect(2, 2); + + return 0; +} diff --git a/examples/draw/draw.stdin.txt b/examples/draw/draw.stdin.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/draw/draw.stdout.txt b/examples/draw/draw.stdout.txt new file mode 100644 index 0000000..1b89826 --- /dev/null +++ b/examples/draw/draw.stdout.txt @@ -0,0 +1,52 @@ +xxxxxxxxxx +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +xxxxxxxxxx +xxx +x x +x x +x x +xxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +x x +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxx +x x +x x +x x +x x +x x +x x +x x +x x +xxxxxxxxxx +xx +xx diff --git a/examples/euclid/euclid.mc b/examples/euclid/euclid.mc new file mode 100644 index 0000000..941c025 --- /dev/null +++ b/examples/euclid/euclid.mc @@ -0,0 +1,45 @@ +int euclid(int n, int k) +{ + if (k == 0) { + return n; + } + + if (n == 0) { + return k; + } + + if (n > k) { + return euclid(n - k, k); + } else { + return euclid(n, k - n); + } +} + +int main() +{ + print("Please enter the first number: "); + print_nl(); + + int n; + n = read_int(); + + print("Please enter the second number: "); + print_nl(); + + int k; + k = read_int(); + print_nl(); + + int result; + result = euclid(n, k); + + print("euclid("); + print_int(n); + print(", "); + print_int(k); + print(") = "); + print_int(result); + print_nl(); + + return 0; +} diff --git a/examples/euclid/euclid.stdin.txt b/examples/euclid/euclid.stdin.txt new file mode 100644 index 0000000..1838a66 --- /dev/null +++ b/examples/euclid/euclid.stdin.txt @@ -0,0 +1,2 @@ +1071 +1029 diff --git a/examples/euclid/euclid.stdout.txt b/examples/euclid/euclid.stdout.txt new file mode 100644 index 0000000..e70978f --- /dev/null +++ b/examples/euclid/euclid.stdout.txt @@ -0,0 +1,4 @@ +Please enter the first number: +Please enter the second number: + +euclid(1071, 1029) = 21 diff --git a/examples/euclidean_division/euclidean_division.mc b/examples/euclidean_division/euclidean_division.mc new file mode 100644 index 0000000..9af5f63 --- /dev/null +++ b/examples/euclidean_division/euclidean_division.mc @@ -0,0 +1,44 @@ +/* Divide integer "divisor" by integer "dividend" and output the remainder */ + +int calculate_remainder(int divisor, int dividend) { + while (dividend > divisor) { + dividend = dividend - divisor; + } + return dividend; +} + +/* The divisor must not be smaller than or equal to 0 */ + +int main() { + + print("Enter Dividend:"); + print_nl(); + int dividend; + dividend = read_int(); + print("Enter Divisor:"); + print_nl(); + int divisor; + divisor = read_int(); + + if (dividend < divisor) { + print("Dividend has to be bigger than divisor."); + print_nl(); + + } else { + + int remainder; + remainder = calculate_remainder(divisor, dividend); + int result; + result = (dividend - remainder) / divisor; + print_int(dividend); + print(" is divisible by "); + print_int(divisor); + print(" with the remainder "); + print_int(remainder); + print(" and result "); + print_int(result); + print_nl(); + } + + return 0; +} diff --git a/examples/euclidean_division/euclidean_division.stdin.txt b/examples/euclidean_division/euclidean_division.stdin.txt new file mode 100644 index 0000000..2e113ca --- /dev/null +++ b/examples/euclidean_division/euclidean_division.stdin.txt @@ -0,0 +1,2 @@ +15 +6 diff --git a/examples/euclidean_division/euclidean_division.stdout.txt b/examples/euclidean_division/euclidean_division.stdout.txt new file mode 100644 index 0000000..ef8c7a5 --- /dev/null +++ b/examples/euclidean_division/euclidean_division.stdout.txt @@ -0,0 +1,3 @@ +Enter Dividend: +Enter Divisor: +15 is divisible by 6 with the remainder 3 and result 2 diff --git a/examples/factorial/factorial.mc b/examples/factorial/factorial.mc new file mode 100644 index 0000000..aac4028 --- /dev/null +++ b/examples/factorial/factorial.mc @@ -0,0 +1,29 @@ +int calculateFactorial(int number){ + int factorial = 1; + int i = 1; + while (i <= number){ + factorial *= i; + i = i + 1; + } + return factorial; +} + +int main() { + + print("Please enter a number: "); + + int number; + number = read_int(); + print_nl(); + + int result; + result = calculateFactorial(number); + + print("The factorial of "); + print_int(number); + print(" is "); + print_int(result); + print_nl(); + + return 0; +} diff --git a/examples/factorial/factorial.stdin.txt b/examples/factorial/factorial.stdin.txt new file mode 100644 index 0000000..3d2c52f --- /dev/null +++ b/examples/factorial/factorial.stdin.txt @@ -0,0 +1 @@ +5 diff --git a/examples/factorial/factorial.stdout.txt b/examples/factorial/factorial.stdout.txt new file mode 100644 index 0000000..e473d65 --- /dev/null +++ b/examples/factorial/factorial.stdout.txt @@ -0,0 +1,2 @@ +Please enter a number: +The factorial of 5 is 120 diff --git a/examples/flw/flw.mc b/examples/flw/flw.mc new file mode 100644 index 0000000..6615b00 --- /dev/null +++ b/examples/flw/flw.mc @@ -0,0 +1,98 @@ +void print_2_signals(float[64] signal1, float[64] signal2) +{ + int i; + float j; + j = 1; + float dec; + dec = 1.0 / 16.0; + while (j > -0.001) + { + i = 0; + while (i < 64) + { + if (signal2[i] < j + 0.5 * dec && signal2[i] > j - 0.5 * dec) + { + print("o"); + } + else if (signal1[i] < j + 0.5 * dec && signal1[i] > j - 0.5 * dec) + { + print("#"); + } + else if (j < 0.5 * dec && j > -0.5 * dec) + { + print("-"); + } + else + { + print(" "); + } + i = i + 1; + } + print_nl(); + j = j - dec; + } +} + +void make_gate(float[64] signal) +{ + int i; + i = 0; + while (i < 64) + { + if (i < 32) + { + signal[i] = 1.0; + } + else + { + signal[i] = 0.0; + } + i = i + 1; + } +} + +void follower(float[64] in, float[64] out, float a, float r) +{ + float p; + p = 0.0; + int i; + i = 0; + while (i < 64) + { + if (in[i] > p) + { + p = a * p + (1.0 - a) * in[i]; + } + else + { + p = r * p + (1.0 - r) * in[i]; + } + out[i] = p; + i = i + 1; + } +} + +int main() +{ + print("Enter Envelope Attack value between 0 and 1 (infinity): "); + float a; + a = read_float(); + print_nl(); + print("Enter Envelope Release value between 0 and 1 (infinity): "); + float r; + r = read_float(); + print_nl(); + print("Resulting Envelope Follower:"); + print_nl(); + print_nl(); + + float[64] gate; + make_gate(gate); + + float[64] envelope; + follower(gate, envelope, a, r); + + print_2_signals(gate, envelope); + + return 0; +} diff --git a/examples/flw/flw.stdin.txt b/examples/flw/flw.stdin.txt new file mode 100644 index 0000000..fee4d81 --- /dev/null +++ b/examples/flw/flw.stdin.txt @@ -0,0 +1,2 @@ +0.9 +0.9 diff --git a/examples/flw/flw.stdout.txt b/examples/flw/flw.stdout.txt new file mode 100644 index 0000000..3276b06 --- /dev/null +++ b/examples/flw/flw.stdout.txt @@ -0,0 +1,21 @@ +Enter Envelope Attack value between 0 and 1 (infinity): +Enter Envelope Release value between 0 and 1 (infinity): +Resulting Envelope Follower: + +################################ + oooooooooo + ooooo o + ooo o + oo + oo o + oo o + o o + o o + oo oo + o o + oo + o ooo + o ooo +o ooooo + oooooooooo +--------------------------------################################ diff --git a/examples/gcd/gcd.mc b/examples/gcd/gcd.mc new file mode 100644 index 0000000..12c3aa6 --- /dev/null +++ b/examples/gcd/gcd.mc @@ -0,0 +1,43 @@ +/* calulcate modulo */ +int mod(int a, int b){ + return a-(a/b*b); +} + +/* calulate greatest common divisor */ +int gcd(int x, int y){ + int c; + if (x < 0){ + x = -x; + } + + if (y < 0){ + y = -y; + } + + while (y != 0) { + c = mod(x, y); + x = y; + y = c; + } + return x; +} + +int main() { + int a; + int b; + + print("Please enter the first number: "); + print_nl(); + a = read_int(); + print("Please enter the second number: "); + print_nl(); + b = read_int(); + + int res = gcd(a,b); + + print("The greatest common divisor is: "); + print_int(res); + print_nl(); + + return 0; +} diff --git a/examples/gcd/gcd.stdin.txt b/examples/gcd/gcd.stdin.txt new file mode 100644 index 0000000..349103a --- /dev/null +++ b/examples/gcd/gcd.stdin.txt @@ -0,0 +1,2 @@ +10 +15 diff --git a/examples/gcd/gcd.stdout.txt b/examples/gcd/gcd.stdout.txt new file mode 100644 index 0000000..ab85e07 --- /dev/null +++ b/examples/gcd/gcd.stdout.txt @@ -0,0 +1,3 @@ +Please enter the first number: +Please enter the second number: +The greatest common divisor is: 5 diff --git a/examples/intToBin/intToBin.mc b/examples/intToBin/intToBin.mc new file mode 100644 index 0000000..d03198d --- /dev/null +++ b/examples/intToBin/intToBin.mc @@ -0,0 +1,61 @@ +/* + * Example input, written in mC + * + * This program coverts three non-negative integers (entered by the user) into their binary representation. + * The result is printed to the console. + */ + +void convert2bin(int number){ + /*Recursive conversion of an integer into binary*/ + + if (number!=0){ + int quot; + quot = number/2; + + if(quot>0){ + convert2bin(quot); + } + + int remainder; + remainder=number-2*quot; + + print_int(remainder); + } + else{ + print_int(0); + } +} + +int main() +{ + int[3] array; + int counter; + counter=1; + + /* Get user input*/ + while(counter<=3){ + print("Enter a non-negative integer ("); + print_int(counter); + print(" of 3): "); + + array[counter-1]=read_int(); + counter=counter+1; + + } + + print_nl(); + /* Compute binary numbers and print them*/ + counter=0; + + while(counter<3){ + print("Binary representation of "); + print_int(array[counter]); + print(": "); + + convert2bin(array[counter]); + print_nl(); + counter=counter+1; + } + + return 0; +} diff --git a/examples/intToBin/intToBin.stdin.txt b/examples/intToBin/intToBin.stdin.txt new file mode 100644 index 0000000..ae4f19d --- /dev/null +++ b/examples/intToBin/intToBin.stdin.txt @@ -0,0 +1,3 @@ +42 +255 +150595 diff --git a/examples/intToBin/intToBin.stdout.txt b/examples/intToBin/intToBin.stdout.txt new file mode 100644 index 0000000..78e223a --- /dev/null +++ b/examples/intToBin/intToBin.stdout.txt @@ -0,0 +1,4 @@ +Enter a non-negative integer (1 of 3): Enter a non-negative integer (2 of 3): Enter a non-negative integer (3 of 3): +Binary representation of 42: 101010 +Binary representation of 255: 11111111 +Binary representation of 150595: 100100110001000011 diff --git a/examples/is_square/is_square.mc b/examples/is_square/is_square.mc new file mode 100644 index 0000000..646e5a1 --- /dev/null +++ b/examples/is_square/is_square.mc @@ -0,0 +1,29 @@ +/* is_squared returns true if a number is the square of any integer */ + +bool is_square(int n) +{ + int i = 0; + while(i*i < n){ + if(i*i == n){ + return true; + } + i = i + 1; + } + return false; +} + +int main() +{ + print("Please enter a number: "); + print_nl(); + int n; + n = read_int(); + if(is_square(n)){ + print("Yes"); + } + else + { + print("No"); + } + print_nl(); +} diff --git a/examples/is_square/is_square.stdin.txt b/examples/is_square/is_square.stdin.txt new file mode 100644 index 0000000..b6a7d89 --- /dev/null +++ b/examples/is_square/is_square.stdin.txt @@ -0,0 +1 @@ +16 diff --git a/examples/is_square/is_square.stdout.txt b/examples/is_square/is_square.stdout.txt new file mode 100644 index 0000000..0950be4 --- /dev/null +++ b/examples/is_square/is_square.stdout.txt @@ -0,0 +1,2 @@ +Please enter a number: +No diff --git a/examples/nim/nim.mc b/examples/nim/nim.mc new file mode 100644 index 0000000..344c5d4 --- /dev/null +++ b/examples/nim/nim.mc @@ -0,0 +1,144 @@ +/* + The computers realy stupid strategy + It is only able to win if the human lets the computer make the first move +*/ +int computer_strategy(int pile, int human_last_choice) +{ + int choice; + + if(human_last_choice == 0) + { + { + { return 2; } + } + } + + choice = 2 * 2 - human_last_choice; + + if( (pile - choice ) < 0 ) + { + return 1; + } + + return choice; +} + +void print_pile_size(int pile) +{ + print("Size of the match stick pile: "); + print_int(pile); + print_nl(); +} + +void print_removal(string player, int choice) +{ + print(player); + print(" removed: "); + print_int(choice); + print_nl(); +} + +void game(int pile, int start) +{ + int human_choice; + int computer_choice; + int next; + + string opponent; + + string computer_chose; + computer_chose = "Computer removed: "; + + string human_chose; + human_chose = "You decided to remove: "; + + if( start == 1 ) + { + opponent = "Human"; + + computer_choice = computer_strategy(pile, 0); + pile = pile - computer_choice; + + print_removal("Computer", computer_choice); + } + + while( pile > 0 ) + { + opponent = "Computer"; + + print_pile_size(pile); + + print("How many match sticks do you want to take away? Between 1 and 3."); + print_nl(); + + human_choice = read_int(); + next = pile - human_choice; + + if( (human_choice <= 3) && ( next >=0 ) ) + { + pile = next; + + print_removal("You", human_choice); + print_pile_size(pile); + + } + else + { + print("Invalid move. You must take between 1 and 3 match sticks. But you tried to take "); + print_int(human_choice); + print(" match sticks"); + print_nl(); + } + + if( human_choice <= 3 && pile>0) + { + + opponent = "Human"; + + computer_choice = computer_strategy(pile, human_choice); + pile = pile - computer_choice; + + print(computer_chose); + print_int(computer_choice); + print_nl(); + } + } + + print(opponent); + print(" wins."); + print_nl(); +} + +int main() +{ + int pile; + int start; + + pile = 15; + + print("NIM: The match stick game"); + print_nl(); + print("........................."); + print_nl(); + + print("Size of the match stick pile: "); + print_int(pile); + print_nl(); + + print("Who should start the game? 0 for You 1 for Computer"); + print_nl(); + start = read_int(); + + if( start < 0 || start > 1 ) + { + print("FAILURE: Start was "); + print_int(start); + print("but should have been between 0 and 1"); + print_nl(); + return 1; + } + + game(pile, start); + + return 0; +} diff --git a/examples/nim/nim.stdin.txt b/examples/nim/nim.stdin.txt new file mode 100644 index 0000000..93dd437 --- /dev/null +++ b/examples/nim/nim.stdin.txt @@ -0,0 +1,6 @@ +0 +14 +2 +2 +2 +2 diff --git a/examples/nim/nim.stdout.txt b/examples/nim/nim.stdout.txt new file mode 100644 index 0000000..ae63f5f --- /dev/null +++ b/examples/nim/nim.stdout.txt @@ -0,0 +1,28 @@ +NIM: The match stick game +......................... +Size of the match stick pile: 15 +Who should start the game? 0 for You 1 for Computer +Size of the match stick pile: 15 +How many match sticks do you want to take away? Between 1 and 3. +Invalid move. You must take between 1 and 3 match sticks. But you tried to take 14 match sticks +Size of the match stick pile: 15 +How many match sticks do you want to take away? Between 1 and 3. +You removed: 2 +Size of the match stick pile: 13 +Computer removed: 2 +Size of the match stick pile: 11 +How many match sticks do you want to take away? Between 1 and 3. +You removed: 2 +Size of the match stick pile: 9 +Computer removed: 2 +Size of the match stick pile: 7 +How many match sticks do you want to take away? Between 1 and 3. +You removed: 2 +Size of the match stick pile: 5 +Computer removed: 2 +Size of the match stick pile: 3 +How many match sticks do you want to take away? Between 1 and 3. +You removed: 2 +Size of the match stick pile: 1 +Computer removed: 1 +Human wins. diff --git a/examples/nonsense/nonsense.mc b/examples/nonsense/nonsense.mc new file mode 100644 index 0000000..4515f3b --- /dev/null +++ b/examples/nonsense/nonsense.mc @@ -0,0 +1,61 @@ +int returnTwo() { + int value = 2; + return value; +} + +bool isOne(int in) { + if (in == 1) + return true; + else + return false; +} + +int main() { + int[42] array; + int[21] arrayTwo; + int i = 0; + while (i < 21) { + array[i] = i*i; + i = i + 1; + } + i = 0; + while (i < 21) { + arrayTwo[i] = array[i]; + i = i + 1; + } + + print_int(array[20]); + print_nl(); + + if (array[0] == 0) { + print_int(array[0]); + print_nl(); + } + + if (array[1] == 2) { + print_int(0); + print_nl(); + } else { + print_int(array[1]); + print_nl(); + } + + if (!isOne(2)) { + print_int(returnTwo()); + print_nl(); + } + + int b; + int a; + b = 2 + 3; + b = -b; + print_int(b); + print_nl(); + a = b; + b = b * b; + if (a == (b/a)) { + print_int(b); + print_nl(); + } + return 0; +} diff --git a/examples/nonsense/nonsense.stdin.txt b/examples/nonsense/nonsense.stdin.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/nonsense/nonsense.stdout.txt b/examples/nonsense/nonsense.stdout.txt new file mode 100644 index 0000000..64e156e --- /dev/null +++ b/examples/nonsense/nonsense.stdout.txt @@ -0,0 +1,6 @@ +400 +0 +1 +2 +-5 +25 diff --git a/examples/palindrome/palindrome.mc b/examples/palindrome/palindrome.mc new file mode 100644 index 0000000..b32f857 --- /dev/null +++ b/examples/palindrome/palindrome.mc @@ -0,0 +1,45 @@ + +int modulo(int n, int k) { + return (n - k * (n / k)); +} + +bool is_palindrome(int original) { + int reversed; + int remainder; + int to_check; + + reversed = 0; + to_check = original; + + while (to_check != 0) { + remainder = modulo(to_check, 10); + reversed = reversed * 10 + remainder; + to_check = to_check / 10; + } + + if (original == reversed) { + return true; + } else { + return false; + } +} + +int main() { + int input; + + print("Please enter a number:"); + input = read_int(); + print_nl(); + + bool result = is_palindrome(input); + + print_int(input); + if (result) { + print(" is a palindrome."); + } else { + print(" is not a palindrome."); + } + print_nl(); + + return 0; +} diff --git a/examples/palindrome/palindrome.stdin.txt b/examples/palindrome/palindrome.stdin.txt new file mode 100644 index 0000000..dd5cfff --- /dev/null +++ b/examples/palindrome/palindrome.stdin.txt @@ -0,0 +1 @@ +4321234 diff --git a/examples/palindrome/palindrome.stdout.txt b/examples/palindrome/palindrome.stdout.txt new file mode 100644 index 0000000..c4dd274 --- /dev/null +++ b/examples/palindrome/palindrome.stdout.txt @@ -0,0 +1,2 @@ +Please enter a number: +4321234 is a palindrome. diff --git a/examples/slowsort/slowsort.mc b/examples/slowsort/slowsort.mc new file mode 100644 index 0000000..eb8ebc1 --- /dev/null +++ b/examples/slowsort/slowsort.mc @@ -0,0 +1,151 @@ +/* implementation of slowsort on integers, based on https://en.wikipedia.org/wiki/Slowsort */ +void i_slowsort(int[10] arr, int i, int j){ + if (i >= j){ + return; + } + int m; + m = (i+j) / 2; + i_slowsort(arr, i, m); + i_slowsort(arr, m+1, j); + if (arr[j] < arr[m]){ /* swap elements on index j and m */ + int tmp; + tmp = arr[j]; + arr[j] = arr[m]; + arr[m] = tmp; + } + j = j - 1; + i_slowsort(arr, i, j); + return; +} + +/* implementation of slowsort on floats, based on https://en.wikipedia.org/wiki/Slowsort */ +void f_slowsort(float[10] arr, int i, int j){ + if (i >= j){ + return; + } + int m; + m = (i+j) / 2; + f_slowsort(arr, i, m); + f_slowsort(arr, m+1, j); + if (arr[j] < arr[m]){ /* swap elements on index j and m */ + float tmp; + tmp = arr[j]; + arr[j] = arr[m]; + arr[m] = tmp; + } + j = j - 1; + f_slowsort(arr, i, j); + return; +} + +/* prints int array to stdout */ +void print_i_array(int[10] arr, int arr_size){ + int i; + i = 0; + while(i < arr_size){ + print_int(arr[i]); + print(" "); + i = i+1; + } + print_nl(); +} + +/* prints float array to stdout */ +void print_f_array(float[10] arr, int arr_size){ + int i; + i = 0; + while(i < arr_size){ + print_float(arr[i]); + print(" "); + i = i+1; + } + print_nl(); +} + +int get_choice(){ + print("Do you want to sort: "); + print_nl(); + print("[1] integers, or"); + print_nl(); + print("[2] floats?"); + print_nl(); + print("choice: "); + print_nl(); + int choice; + choice = read_int(); + return choice; +} + +int main(){ + print("*** Implementation of Slowsort ***"); + print_nl(); + + /* get user choice */ + int choice; + choice = get_choice(); + + bool is_int; + if (choice == 1){ + is_int = true; + }else if (choice == 2){ + is_int = false; + }else{ + print("Invalid choice! Choice have to be either 1, or 2."); + print_nl(); + return 0; + } + print("give a sequence of 10 numbers to be sorted: "); + print_nl(); + + int arr_size = 10; + int i; + i=0; + + if (is_int){ + int i_arr[arr_size]; + int i_number; + while(i < arr_size){ + print_int(i); + print(". number = "); + print_nl(); + i_number = read_int(); + i_arr[i] = i_number; + i = i+1; + } + + /* print input array to stdout */ + print("input array: "); + print_i_array(i_arr, arr_size); + + /* call sorting function */ + i_slowsort(i_arr, 0, arr_size-1); + + /* print result array to stdout */ + print("output array: "); + print_i_array(i_arr, arr_size); + }else{ + float f_arr[arr_size]; + float f_number; + + while(i < arr_size){ + print_int(i); + print(". number = "); + f_number = read_float(); + f_arr[i] = f_number; + i = i+1; + } + + /* print input array to stdout */ + print("input array: "); + print_f_array(f_arr, arr_size); + + /* call sorting function */ + f_slowsort(f_arr, 0, arr_size-1); + + /* print result array to stdout */ + print("output array: "); + print_f_array(f_arr, arr_size); + } + + return 0; +} diff --git a/examples/slowsort/slowsort.stdin.txt b/examples/slowsort/slowsort.stdin.txt new file mode 100644 index 0000000..2d50b6a --- /dev/null +++ b/examples/slowsort/slowsort.stdin.txt @@ -0,0 +1,11 @@ +1 +25 +35435 +232 +12435 +25 +678 +96854 +1 +456 +77777 diff --git a/examples/slowsort/slowsort.stdout.txt b/examples/slowsort/slowsort.stdout.txt new file mode 100644 index 0000000..dbd2b0a --- /dev/null +++ b/examples/slowsort/slowsort.stdout.txt @@ -0,0 +1,18 @@ +*** Implementation of Slowsort *** +Do you want to sort: +[1] integers, or +[2] floats? +choice: +give a sequence of 10 numbers to be sorted: +0. number = +1. number = +2. number = +3. number = +4. number = +5. number = +6. number = +7. number = +8. number = +9. number = +input array: 25 35435 232 12435 25 678 96854 1 456 77777 +output array: 1 25 25 232 456 678 12435 35435 77777 96854 diff --git a/examples/supersyntaxchecker2000/supersyntaxchecker2000.mc b/examples/supersyntaxchecker2000/supersyntaxchecker2000.mc new file mode 100644 index 0000000..23c16c1 --- /dev/null +++ b/examples/supersyntaxchecker2000/supersyntaxchecker2000.mc @@ -0,0 +1,34 @@ +/* This is a comment */ +int main(){ + print("Please enter a number: "); + print_nl(); + int n; + n = read_int(); + bool a = 1 <= n; + bool b = 2 == n; + b = 3 >= n; + n = n * 2; + n = n / 2; + n = n + 2; + n = n - 2; + a && b; + a || b; + a != !b; + int[3] test; + string hi = "Hello"; + float f = -1.0; + bool c = true; + if (c) + { + while(c){ + c = false; + } + } + if (c){ + f = f * 2; + } + else{ + f = f * 3; + } + return 0; +} diff --git a/examples/supersyntaxchecker2000/supersyntaxchecker2000.stdin.txt b/examples/supersyntaxchecker2000/supersyntaxchecker2000.stdin.txt new file mode 100644 index 0000000..12cf442 --- /dev/null +++ b/examples/supersyntaxchecker2000/supersyntaxchecker2000.stdin.txt @@ -0,0 +1 @@ +20 diff --git a/examples/supersyntaxchecker2000/supersyntaxchecker2000.stdout.txt b/examples/supersyntaxchecker2000/supersyntaxchecker2000.stdout.txt new file mode 100644 index 0000000..d9095ac --- /dev/null +++ b/examples/supersyntaxchecker2000/supersyntaxchecker2000.stdout.txt @@ -0,0 +1 @@ +Please enter a number: