From: Doni Pracner Date: Wed, 18 Jan 2023 00:32:57 +0000 (+0100) Subject: expanded sample size, first version X-Git-Tag: v1.1.1^0 X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=HEAD;p=mjc2wsl.git expanded sample size, first version --- 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