-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.java
More file actions
73 lines (61 loc) · 1.68 KB
/
Copy pathGrid.java
File metadata and controls
73 lines (61 loc) · 1.68 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
package y2016.d08;
import y2015.d06.Instruction;
public class Grid {
private boolean[][] grid = new boolean[6][50];
public void rect(int x, int y) {
for (int i = 0; i < y; i++) {
for (int j = 0; j < x; j++) {
grid[i][j] = true;
}
}
}
public void rect(String x, String y) {
rect(
Integer.parseInt(x),
Integer.parseInt(y)
);
}
public void rotRow (int row, int length) {
boolean[] newRow = new boolean[50];
for (int i = 0; i < 50; i++) {
newRow[(i+length) % 50] = grid[row][i];
}
grid[row] = newRow;
}
public void rotRow (String row, String length) {
rotRow(
Integer.parseInt(row),
Integer.parseInt(length)
);
}
public void rotCol (int col, int length) {
boolean[] newCol = new boolean[6];
for (int i = 0; i < 6; i++) {
newCol[(i+length)%6] = grid[i][col];
}
for (int i = 0; i < 6; i++) {
grid[i][col] = newCol[i];
}
}
public void rotCol (String col, String length) {
rotCol(
Integer.parseInt(col),
Integer.parseInt(length)
);
}
public void print() {
int count = 0;
for (boolean[] row: grid) {
for (boolean cell: row) {
if (cell) {
System.out.print('#');
++count;
} else {
System.out.print('.');
}
}
System.out.println();
}
System.out.println("on: " + count);
}
}