Commit 1970db39 authored by ucywg's avatar ucywg
Browse files

compile-firm tests from group 3

parent ba463b3d
Pipeline #180607 failed with stage
in 17 minutes and 49 seconds
class Ackermann
{
public int ack(int m, int n)
{
if (m == 0)
{
return n + 1;
}
else if((m > 0) && (n == 0))
{
return ack(m - 1, 1);
}
else if((m > 0) && (n > 0))
{
return ack(m - 1, ack(m, n - 1));
}else {
System.out.println(m);
return n + 1;
}
}
public static void main(String[] args)
{
Ackermann a = new Ackermann();
System.out.println(a.ack(2,1));
System.out.println(a.ack(2,2));
System.out.println(a.ack(3,3));
System.out.println(a.ack(3,8));
System.out.println(a.ack(4,4));
}
}
class Ackermann
{
public int ack(int m, int n)
{
if (m == 0)
{
return n + 1;
}
else if((m > 0) && (n == 0))
{
return ack(m - 1, 1);
}
else if((m > 0) && (n > 0))
{
return ack(m - 1, ack(m, n - 1));
}else {
System.out.println(m);
return n + 1;
}
}
public static void main(String[] args)
{
Ackermann a = new Ackermann();
System.out.println(a.ack(2,1));
System.out.println(a.ack(2,2));
System.out.println(a.ack(3,3));
System.out.println(a.ack(3,8));
}
}
class A {
public int b;
public int a() {
return b = 4;
}
}
class B {
public static void main(String[] args) {
A a = new A();
System.out.println(a.a());
}
}
\ No newline at end of file
class Factorial{
public static void main(String[] s) {
int i = 1;
int fact = 1;
int number=5;
while(i < number) {
fact=fact*i;
i = i+1;
}
System.out.println(fact);
}
}
\ No newline at end of file
class LinkedList {
public static void main(String[] args) {
List list = new List();
list.init();
int i = 0;
while (i < 100) {
list.insert(i);
i = i + 1;
}
int[] result = list.intoArray();
int j = 0;
while (j < list.size) {
System.out.println(result[j]);
j = j + 1;
}
}
}
class Node {
public int val;
public Node next;
}
class List {
public Node node;
public int size;
public void init() {
this.node = new Node();
}
public void insert(int val) {
Node start = node;
node = new Node();
node.val = val;
node.next = start;
size = size + 1;
}
public int[] intoArray() {
int[] result = new int[size];
int i = size;
Node current = node;
while (i > 0) {
i = i - 1;
result[i] = current.val;
current = current.next;
}
return result;
}
}
class Math {
public static void main(String[] args) {
int division1 = 200 / 10;
int division2 = division1 / 4;
int division3 = division1 / division2;
System.out.println(division3);
division1 = 200 / 10;
division2 = division1 / 1;
division3 = division1 / division2;
System.out.println(division3);
int a = 5;
int b = 3;
int c = a % b + 1;
System.out.println(c);
}
}
\ No newline at end of file
class A {
public int x;
public B b;
public static void main(String[] args) {
A instance = new A();
instance.b = new B();
while (instance.call(instance.b) > 0) {
if (instance.x == 0) {
System.out.println(0);
}
instance.doSomething();
}
}
public int call(B val) {
return x + val.val();
}
public void doSomething() {
this.x = x - 1;
}
}
class B {
public int val() {
return 1;
}
}
class QuickSort {
public void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public int partition(int[] arr, int low, int high) {
int pivot = arr[high];
int i = (low - 1);
int j = low;
while (j <= high - 1) {
if (arr[j] < pivot) {
i = i + 1;
swap(arr, i, j);
}
j = j + 1;
}
swap(arr, i + 1, high);
return (i + 1);
}
public void quickSort(int[] arr, int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
public void printArray(int[] arr, int size) {
int i = 0;
while (i < size) {
System.out.println(arr[i]);
i = i + 1;
}
System.out.println(-1);
}
}
class RNG {
public int currentVal;
public void init(int seed) {
currentVal = next(seed);
}
public int get() {
return currentVal;
}
public int getNext() {
currentVal = next(currentVal);
return currentVal;
}
/* private */ public int next(int val) {
int _primeFactor = 57203;
int _16Bit = 256 * 256;
val = val * _primeFactor;
int upper = val * _16Bit;
int lower = val / _16Bit;
lower = lower * 31;
return upper + lower + 7;
}
}
class B {
public static void main(String[] args) {
QuickSort q = new QuickSort();
B m = new B();
int size = 50;
int[] sequence = m.randomSequence(1, size);
q.printArray(sequence, size);
q.quickSort(sequence, 0, size - 1);
q.printArray(sequence, size);
}
public int[] randomSequence(int seed, int len) {
int _18Bit = 256 * 256 * 4;
RNG rng = new RNG();
rng.init(seed);
int[] result = new int[len];
int i = 0;
while (i < len) {
int num = rng.getNext() / _18Bit;
if (num < 0) {
num = -num;
}
result[i] = num;
i = i + 1;
}
return result;
}
}
\ No newline at end of file
class Main {
public static void main(String[] args) {
Main m = new Main();
int[] sequence = m.randomSequence(1, 100);
int i = 0;
while (i < 100) {
System.out.println(sequence[i]);
i = i + 1;
}
}
public int[] randomSequence(int seed, int len) {
int _18Bit = 256 * 256 * 4;
RNG rng = new RNG();
rng.init(seed);
int[] result = new int[len];
int i = 0;
while (i < len) {
int num = rng.getNext() / _18Bit;
if (num < 0) {
num = -num;
}
result[i] = num;
i = i + 1;
}
return result;
}
}
class RNG {
public int currentVal;
public void init(int seed) {
currentVal = next(seed);
}
public int get() {
return currentVal;
}
public int getNext() {
currentVal = next(currentVal);
return currentVal;
}
/* private */ public int next(int val) {
int _primeFactor = 57203;
int _16Bit = 256 * 256;
val = val * _primeFactor;
int upper = val * _16Bit;
int lower = val / _16Bit;
lower = lower * 31;
return upper + lower + 7;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment