import java.util.*;
class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
print2D(determineWinner(5,5));
System.out.println(climbStairs(4));
}
public static Boolean[][] determineWinner(int p, int q) {
Boolean[][] matrix = new Boolean[p+1][q+1];
// starting cases
matrix[0][0] = false;
matrix[1][0] = true;
matrix[0][1] = true;
for (int i = 0; i < p+1; i++) {
for (int j = 0; j < q+1; j++) {
if (matrix[i][j] == null) {
//if pile 1 has no more stones
if (i == 0) {
matrix[i][j] = matrix[i][j-1] ? false : true;
}
// if pile 2 has no more stones
else if (j == 0) {
matrix[i][j] = matrix[i-1][j] ? false : true;
}
// if pile 1 and 2 have at least 1 stone
else {
// can either take 1 stone from i, 1 stone from j, or 1 stone from both i and j
Boolean[] neighboring_moves = {matrix[i-1][j], matrix[i][j-1], matrix[i-1][j-1]};
boolean found = false;
for(boolean b : neighboring_moves) {
if (!b) {
found = true;
}
} matrix[i][j] = (found) ? true : false;
}
}
}
}
return matrix;
}
public static int climbStairs(int n) {
ArrayList<Integer> arr = new ArrayList<Integer>();
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
if (n == 2) {
return 2;
}
arr.add(0);
arr.add(1);
arr.add(2);
for (int i = 3; i <= n; i++) {
arr.add(arr.get(i-1) + arr.get(i-2));
}
return arr.get(arr.size()-1);
}
public static void print2D(Boolean mat[][])
{
for (Boolean[] row : mat)
// converting each row as string
// and then printing in a separate line
System.out.println(Arrays.toString(row));
}
}