-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockgame2.java
61 lines (48 loc) · 1.1 KB
/
blockgame2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package programming_challenges;
import java.util.Arrays;
public class blockgame2 {
public static void main(String[] args) {
Kattio io = new Kattio(System.in);
long N = io.getInt();
long M = io.getInt();
boolean[][] canWin = new boolean[(int)N+1][(int)M+1];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
if (j == 0 || i == 0) { //base case
canWin[i][j] = false;
continue;
}
if (j == 1 || i == 1) { //base case
canWin[i][j] = true;
continue;
}
if (j%i == 0 || i%j == 0) {
canWin[i][j] = true;
continue;
}
//Look at our possible moves
for (int k = i - j; k > 0; k = k - j) {
if(!canWin[k][j]) {
canWin[i][j] = true;
break;
}
}
if(!canWin[i][j]) {
for (int k = j - i; k > 0; k = k - i) {
if(!canWin[i][k]) {
canWin[i][j] = true;
break;
}
}
}
}
}
//System.out.println(Arrays.deepToString(canWin));
if (canWin[(int)N][(int)M]) {
System.out.println("win");
} else {
System.out.println("lose");
}
io.close();
}
}