From 1601c2c11f9f93dbb8c6d64c9e584c5dd42f79c6 Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Wed, 18 Jan 2023 01:32:57 +0100 Subject: [PATCH] expanded sample size, first version --- samples/alpha-mj-exp/ArrayTest.mj | 20 +++ samples/alpha-mj-exp/ArraysTest.mj | 29 ++++ samples/alpha-mj-exp/InOut1.mj | 9 ++ samples/alpha-mj-exp/InOut2.mj | 10 ++ samples/alpha-mj-exp/InOut3.mj | 23 +++ samples/alpha-mj-exp/Palindromes.mj | 171 ++++++++++++++++++++++ samples/alpha-mj-exp/PalindromesList.mj | 116 +++++++++++++++ samples/alpha-mj-exp/Parentheses.mj | 44 ++++++ samples/alpha-mj-exp/QuickSort.mj | 76 ++++++++++ samples/alpha-mj-exp/Rek1.mj | 11 ++ samples/alpha-mj-exp/RekFac.mj | 17 +++ samples/alpha-mj-exp/RekFib.mj | 18 +++ samples/alpha-mj-exp/SortColors.mj | 64 ++++++++ samples/alpha-mj-exp/chrtest.mj | 11 ++ samples/alpha-mj-exp/div0.mj | 11 ++ samples/alpha-mj-exp/div2.mj | 11 ++ samples/alpha-mj-exp/eratos.mj | 47 ++++++ samples/alpha-mj-exp/fields.mj | 44 ++++++ samples/alpha-mj-exp/gcd-proc-input.mj | 26 ++++ samples/alpha-mj-exp/gcd-proc-predef.mj | 20 +++ samples/alpha-mj-exp/gcd-rek-input.mj | 24 +++ samples/alpha-mj-exp/gcd-rek-predef-m3.mj | 18 +++ samples/alpha-mj-exp/linkedlist.mj | 85 +++++++++++ samples/alpha-mj-exp/max-arr.mj | 60 ++++++++ samples/alpha-mj-exp/pos-neg.mj | 42 ++++++ samples/alpha-mj-exp/sort-insert.mj | 58 ++++++++ samples/alpha-mj-exp/sort-selection.mj | 63 ++++++++ samples/alpha-mj-exp/while-print.mj | 12 ++ tests/alpha-mj-exp/ArrayTest.txt | 0 tests/alpha-mj-exp/ArraysTest.txt | 0 tests/alpha-mj-exp/InOut1.txt | 1 + tests/alpha-mj-exp/InOut2.txt | 1 + tests/alpha-mj-exp/InOut3.1.txt | 2 + tests/alpha-mj-exp/InOut3.2.txt | 2 + tests/alpha-mj-exp/Palindromes1.txt | 16 ++ tests/alpha-mj-exp/Palindromes2.txt | 15 ++ tests/alpha-mj-exp/Palindromes3.txt | 7 + tests/alpha-mj-exp/PalindromesList1.txt | 16 ++ tests/alpha-mj-exp/PalindromesList2.txt | 7 + tests/alpha-mj-exp/PalindromesList3.txt | 25 ++++ tests/alpha-mj-exp/Parentheses1.txt | 1 + tests/alpha-mj-exp/Parentheses2.txt | 1 + tests/alpha-mj-exp/QuickSort.txt | 8 + tests/alpha-mj-exp/Rek1.txt | 0 tests/alpha-mj-exp/RekFac.txt | 0 tests/alpha-mj-exp/RekFib.txt | 0 tests/alpha-mj-exp/SortColors.txt | 7 + tests/alpha-mj-exp/chrtest.txt | 0 tests/alpha-mj-exp/div0.txt | 0 tests/alpha-mj-exp/div2.txt | 0 tests/alpha-mj-exp/eratos.1.txt | 1 + tests/alpha-mj-exp/eratos.2.txt | 1 + tests/alpha-mj-exp/eratos.3.txt | 1 + tests/alpha-mj-exp/fields.txt | 0 tests/alpha-mj-exp/gcd-proc-input1.txt | 2 + tests/alpha-mj-exp/gcd-proc-input2.txt | 3 + tests/alpha-mj-exp/gcd-proc-input3.txt | 2 + tests/alpha-mj-exp/gcd-proc-predef.txt | 0 tests/alpha-mj-exp/gcd-rek-input1.txt | 2 + tests/alpha-mj-exp/gcd-rek-input2.txt | 3 + tests/alpha-mj-exp/gcd-rek-input3.txt | 2 + tests/alpha-mj-exp/gcd-rek-predef-m3.txt | 0 tests/alpha-mj-exp/linkedlist.1.txt | 1 + tests/alpha-mj-exp/linkedlist.2.txt | 7 + tests/alpha-mj-exp/linkedlist.3.txt | 7 + tests/alpha-mj-exp/max-arr.txt | 5 + tests/alpha-mj-exp/pos-neg.1.txt | 6 + tests/alpha-mj-exp/pos-neg.2.txt | 8 + tests/alpha-mj-exp/pos-neg.3.txt | 3 + tests/alpha-mj-exp/sort-insert1.txt | 5 + tests/alpha-mj-exp/sort-insert2.txt | 5 + tests/alpha-mj-exp/sort-selection.txt | 11 ++ tests/alpha-mj-exp/while-print.txt | 0 73 files changed, 1324 insertions(+) create mode 100644 samples/alpha-mj-exp/ArrayTest.mj create mode 100644 samples/alpha-mj-exp/ArraysTest.mj create mode 100644 samples/alpha-mj-exp/InOut1.mj create mode 100644 samples/alpha-mj-exp/InOut2.mj create mode 100644 samples/alpha-mj-exp/InOut3.mj create mode 100644 samples/alpha-mj-exp/Palindromes.mj create mode 100644 samples/alpha-mj-exp/PalindromesList.mj create mode 100644 samples/alpha-mj-exp/Parentheses.mj create mode 100644 samples/alpha-mj-exp/QuickSort.mj create mode 100644 samples/alpha-mj-exp/Rek1.mj create mode 100644 samples/alpha-mj-exp/RekFac.mj create mode 100644 samples/alpha-mj-exp/RekFib.mj create mode 100644 samples/alpha-mj-exp/SortColors.mj create mode 100644 samples/alpha-mj-exp/chrtest.mj create mode 100644 samples/alpha-mj-exp/div0.mj create mode 100644 samples/alpha-mj-exp/div2.mj create mode 100644 samples/alpha-mj-exp/eratos.mj create mode 100644 samples/alpha-mj-exp/fields.mj create mode 100644 samples/alpha-mj-exp/gcd-proc-input.mj create mode 100644 samples/alpha-mj-exp/gcd-proc-predef.mj create mode 100644 samples/alpha-mj-exp/gcd-rek-input.mj create mode 100644 samples/alpha-mj-exp/gcd-rek-predef-m3.mj create mode 100644 samples/alpha-mj-exp/linkedlist.mj create mode 100644 samples/alpha-mj-exp/max-arr.mj create mode 100644 samples/alpha-mj-exp/pos-neg.mj create mode 100644 samples/alpha-mj-exp/sort-insert.mj create mode 100644 samples/alpha-mj-exp/sort-selection.mj create mode 100644 samples/alpha-mj-exp/while-print.mj create mode 100644 tests/alpha-mj-exp/ArrayTest.txt create mode 100644 tests/alpha-mj-exp/ArraysTest.txt create mode 100644 tests/alpha-mj-exp/InOut1.txt create mode 100644 tests/alpha-mj-exp/InOut2.txt create mode 100644 tests/alpha-mj-exp/InOut3.1.txt create mode 100644 tests/alpha-mj-exp/InOut3.2.txt create mode 100644 tests/alpha-mj-exp/Palindromes1.txt create mode 100644 tests/alpha-mj-exp/Palindromes2.txt create mode 100644 tests/alpha-mj-exp/Palindromes3.txt create mode 100644 tests/alpha-mj-exp/PalindromesList1.txt create mode 100644 tests/alpha-mj-exp/PalindromesList2.txt create mode 100644 tests/alpha-mj-exp/PalindromesList3.txt create mode 100644 tests/alpha-mj-exp/Parentheses1.txt create mode 100644 tests/alpha-mj-exp/Parentheses2.txt create mode 100644 tests/alpha-mj-exp/QuickSort.txt create mode 100644 tests/alpha-mj-exp/Rek1.txt create mode 100644 tests/alpha-mj-exp/RekFac.txt create mode 100644 tests/alpha-mj-exp/RekFib.txt create mode 100644 tests/alpha-mj-exp/SortColors.txt create mode 100644 tests/alpha-mj-exp/chrtest.txt create mode 100644 tests/alpha-mj-exp/div0.txt create mode 100644 tests/alpha-mj-exp/div2.txt create mode 100644 tests/alpha-mj-exp/eratos.1.txt create mode 100644 tests/alpha-mj-exp/eratos.2.txt create mode 100644 tests/alpha-mj-exp/eratos.3.txt create mode 100644 tests/alpha-mj-exp/fields.txt create mode 100644 tests/alpha-mj-exp/gcd-proc-input1.txt create mode 100644 tests/alpha-mj-exp/gcd-proc-input2.txt create mode 100644 tests/alpha-mj-exp/gcd-proc-input3.txt create mode 100644 tests/alpha-mj-exp/gcd-proc-predef.txt create mode 100644 tests/alpha-mj-exp/gcd-rek-input1.txt create mode 100644 tests/alpha-mj-exp/gcd-rek-input2.txt create mode 100644 tests/alpha-mj-exp/gcd-rek-input3.txt create mode 100644 tests/alpha-mj-exp/gcd-rek-predef-m3.txt create mode 100644 tests/alpha-mj-exp/linkedlist.1.txt create mode 100644 tests/alpha-mj-exp/linkedlist.2.txt create mode 100644 tests/alpha-mj-exp/linkedlist.3.txt create mode 100644 tests/alpha-mj-exp/max-arr.txt create mode 100644 tests/alpha-mj-exp/pos-neg.1.txt create mode 100644 tests/alpha-mj-exp/pos-neg.2.txt create mode 100644 tests/alpha-mj-exp/pos-neg.3.txt create mode 100644 tests/alpha-mj-exp/sort-insert1.txt create mode 100644 tests/alpha-mj-exp/sort-insert2.txt create mode 100644 tests/alpha-mj-exp/sort-selection.txt create mode 100644 tests/alpha-mj-exp/while-print.txt diff --git a/samples/alpha-mj-exp/ArrayTest.mj b/samples/alpha-mj-exp/ArrayTest.mj new file mode 100644 index 0000000..c55ffd1 --- /dev/null +++ b/samples/alpha-mj-exp/ArrayTest.mj @@ -0,0 +1,20 @@ +program ArrayTest + int[] arr; + int i; + int max; +{ + void main(){ + max = 10; + arr = new int[max]; + i = 0; + while (i1){ + a = new int[i]; + loc = 0; + loc2 = 1; + while (loc= 97 && ord(s[i]) <= 122) { + letters[ord(s[i]) - 97]++; + } + i++; + } + + oddChar = ' '; + palindrome = new char[len(s)]; + counter = 0; + + i = 0; + ret = 1; + while (i < len(letters) && ret != 0) { + if (letters[i] > 0 && letters[i] % 2 == 0) { + j = 1; + while (j <= letters[i] / 2) { + palindrome[counter] = chr(i + 97); + counter++; + j++; + } + } else if (letters[i] > 0 && oddChar == ' ') { + oddChar = chr(i + 97); + j = 1; + while (j <= letters[i] / 2) { + palindrome[counter] = chr(i + 97); + counter++; + j++; + } + } else if (letters[i] % 2 != 0 && oddChar != ' ') { + ret = 0; + } + + i++; + } + + palindromeRes = copy(palindrome, counter); + + if (ret == 0) { + return null; + } else if (oddChar != ' ') { + return concatA(concatC(palindromeRes, oddChar), reverse(palindromeRes)); + } else { + return concatA(palindromeRes, reverse(palindromeRes)); + } + } + + void main() + char[] input; + int response; + { + input = load(); + printArr(input); + printArr(findPalindrome(input)); + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/PalindromesList.mj b/samples/alpha-mj-exp/PalindromesList.mj new file mode 100644 index 0000000..5501943 --- /dev/null +++ b/samples/alpha-mj-exp/PalindromesList.mj @@ -0,0 +1,116 @@ +program PalindromesList + class Element { + char info; + Element prev, next; + } + + Element first, last; +{ + void initList() { + first = null; + last = null; + } + + void addToEnd(char c) + Element newone; + { + newone = new Element; + newone.info = c; + newone.next = null; + newone.prev = null; + + if (last == null) { + first = newone; + last = newone; + } else { + newone.prev = last; + last.next = newone; + last = newone; + } + } + + void printSubword(Element start, Element end) + Element curr; + { + curr = start; + while (curr != end) { + print(curr.info, 3); + curr = curr.next; + } + print(curr.info, 3); + print('\n'); + } + + int isPalindrome(Element start, Element end) + { + while (start != end && start.next != end) { + if (start.info != end.info) { + return 0; + } else { + start = start.next; + end = end.prev; + } + } + + if (start.info == end.info) { + return 1; + } + return 0; + } + + void printAllPalindromes() + Element start, end; + { + start = first; + while (start != null) { + end = last; + while (end != start) { + if (isPalindrome(start, end) == 1) { + printSubword(start, end); + } + end = end.prev; + } + start = start.next; + } + } + + void printlist() + Element cur; + { + cur = first; + while (cur != null) { + print(cur.info); + cur = cur.next; + } + print('\n'); + } + + void load() + int num, c; + char in; + { + print('l'); + print('?'); + read(num); + c = 0; + while (c right) { + solution[pos] = ')'; + parentheses(solution, pos+1, left, right+1, num); + } + } + + void pars(char[] sln, int num) { + if (num > 0) { + parentheses(sln, 0, 0, 0, num); + } + } + + void main() + int i, dimension; + char[] solution; + { + print('d'); + print('?'); + read(dimension); + solution = new char[2*dimension]; + pars(solution, dimension); + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/QuickSort.mj b/samples/alpha-mj-exp/QuickSort.mj new file mode 100644 index 0000000..a50c25b --- /dev/null +++ b/samples/alpha-mj-exp/QuickSort.mj @@ -0,0 +1,76 @@ +program QuickSort { + int[] load() + int[] res; + int c,num,in; { + print('l'); + print('?'); + read(num); + res = new int[num]; + c = 0; + while (c0) + func(i-1); + } + + void main() { + func(5); + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/RekFac.mj b/samples/alpha-mj-exp/RekFac.mj new file mode 100644 index 0000000..674cc14 --- /dev/null +++ b/samples/alpha-mj-exp/RekFac.mj @@ -0,0 +1,17 @@ +program RekFac{ + + int factorial(int f) + { + if (f<0) + return 0; + if (f<=1) + return 1; + return factorial(f-1) * f ; + } + + void main() + { + print(factorial(3),3); + print(factorial(10),10); + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/RekFib.mj b/samples/alpha-mj-exp/RekFib.mj new file mode 100644 index 0000000..d3a59a5 --- /dev/null +++ b/samples/alpha-mj-exp/RekFib.mj @@ -0,0 +1,18 @@ +program RekFib{ + + int fib(int f) + { + if (f==0) + return 0; + if (f==1) + return 1; + return fib(f-2)+fib(f-1) ; + } + + void main() + { + print(fib(0),3); + print(fib(2),3); + print(fib(7),3); + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/SortColors.mj b/samples/alpha-mj-exp/SortColors.mj new file mode 100644 index 0000000..231e22d --- /dev/null +++ b/samples/alpha-mj-exp/SortColors.mj @@ -0,0 +1,64 @@ +program SortColors { + // array with n objects colored red, white or blue + // sort so that the same colored objects are adjacent + // red, white, blue = 0, 1, 2 (values in array) + + void sortColors(int[] nums) + int p0, p1, p2, temp; + { + p0 = 0; + p1 = 0; + p2 = len(nums) - 1; + + while (p1 <= p2) { + if (nums[p1] == 0) { + temp = nums[p0]; + nums[p0] = nums[p1]; + nums[p1] = temp; + p0 = p0 + 1; + p1 = p1 + 1; + } else if (nums[p1] == 1) { + p1 = p1 + 1; + } else { + temp = nums[p1]; + nums[p1] = nums[p2]; + nums[p2] = temp; + p2 = p2 - 1; + } + } + } + + void printArr(int[] nums) + int i; + { + i = 0; + print('\n'); + print('['); + while (i < len(nums)) { + print(nums[i], 2); + i++; + } + print(']', 2); + } + + void main() + int n, i; + int[] nums; + { + print('n'); + print('?'); + read(n); + nums = new int[n]; + i = 0; + while (i < n) { + print('n'); + print(i); + print('?'); + print(' '); + read(nums[i]); + i++; + } + sortColors(nums); + printArr(nums); + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/chrtest.mj b/samples/alpha-mj-exp/chrtest.mj new file mode 100644 index 0000000..ddc0b8b --- /dev/null +++ b/samples/alpha-mj-exp/chrtest.mj @@ -0,0 +1,11 @@ +program P +{ + void main() + { + print(chr(65),5); + print('A',5); + print(chr(10),2); + print(ord('a'),5); + print('a',5); + } +} diff --git a/samples/alpha-mj-exp/div0.mj b/samples/alpha-mj-exp/div0.mj new file mode 100644 index 0000000..bd92135 --- /dev/null +++ b/samples/alpha-mj-exp/div0.mj @@ -0,0 +1,11 @@ +program test +{ + void main() + int i, j; + { + i = 100; + j = 0; + print(i/j); + } + +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/div2.mj b/samples/alpha-mj-exp/div2.mj new file mode 100644 index 0000000..455b4af --- /dev/null +++ b/samples/alpha-mj-exp/div2.mj @@ -0,0 +1,11 @@ +program test +{ + void main() + int i, j; + { + i = 100; + j = 2; + print(i/j); + } + +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/eratos.mj b/samples/alpha-mj-exp/eratos.mj new file mode 100644 index 0000000..92d28f8 --- /dev/null +++ b/samples/alpha-mj-exp/eratos.mj @@ -0,0 +1,47 @@ +program Eratos + + char[] sieve; + int max; // maximum prime to be found + int npp; // numbers per page + +{ + void put(int x) + { + if (npp == 10) { + print(chr(13)); + print(chr(10)); + npp = 0; + } + print(x, 5); + npp++; + } + + void found(int x) + int i; + { + put(x); + i = x; + while (i <= max) { + sieve[i] = 'o'; i = i + x; + } + } + + void main() + int i; + { + read(max); + npp = 0; + sieve = new char[max+1]; + i = 0; + while (i <= max) { + sieve[i] = 'x'; i++; + } + i = 2; + while (i <= max) { + found(i); + while(i <= max && sieve[i] == 'o') + i++; + } + } + +}//test \ No newline at end of file diff --git a/samples/alpha-mj-exp/fields.mj b/samples/alpha-mj-exp/fields.mj new file mode 100644 index 0000000..f29fb26 --- /dev/null +++ b/samples/alpha-mj-exp/fields.mj @@ -0,0 +1,44 @@ +program F + class HolderClass { + int simple; + int[] arry; + } + + HolderClass holder; + +{ + void main() + int i, size; + { + holder = new HolderClass; + holder.simple = 5; + + print(holder.simple,10); + + print(chr(10)); + + size = 5; + holder.arry = new int[size]; + holder.arry[0] = size+1; + i = 1; + while (i < size){ + holder.arry[i] = holder.arry[i-1]-1; + i++; + } + + i = 0; + while (i < size){ + print(holder.arry[i],3); + i++; + } + print(chr(10)); + + i = 0; + while (i < size){ + holder.arry[i]--; + print(holder.arry[i],3); + i++; + } + + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/gcd-proc-input.mj b/samples/alpha-mj-exp/gcd-proc-input.mj new file mode 100644 index 0000000..ce38aaa --- /dev/null +++ b/samples/alpha-mj-exp/gcd-proc-input.mj @@ -0,0 +1,26 @@ +program procgcdinput{ + + int gcd(int a, int b) + { + while (a != b) { + if (a>b) + a = a-b; + if (ab) + a = a-b; + if (ab) + return gcd(a-b,b); + if (ab) + return gcd(a-b,b); + if (a 0 && t < arr[j-1]) { + arr[j]=arr[j-1]; + j = j - 1; + } + arr[j] = t; + i++; + } + + } + + void main() + int[] arr; + { + arr = load(); + printar(arr); + sort(arr); + printar(arr); + } +} \ No newline at end of file diff --git a/samples/alpha-mj-exp/sort-selection.mj b/samples/alpha-mj-exp/sort-selection.mj new file mode 100644 index 0000000..12abf89 --- /dev/null +++ b/samples/alpha-mj-exp/sort-selection.mj @@ -0,0 +1,63 @@ +program SelectionSort { + int[] load() + int[] res; + int c,num,in; { + print('l'); + print('?'); + read(num); + res = new int[num]; + c = 0; + while (c