-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart1.java
More file actions
40 lines (33 loc) · 1.26 KB
/
Copy pathPart1.java
File metadata and controls
40 lines (33 loc) · 1.26 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
package y2016.d08;
import common.Files;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Part1 {
public static void main(String[] args) throws Exception {
ArrayList<String> lines = Files.readByLines("src/main/java/y2016/d08/in.txt");
Grid grid = new Grid();
Pattern pattern1 = Pattern.compile("(\\d+)x(\\d+)");
Pattern pattern2 = Pattern.compile("=(\\d+) by (\\d+)");
for (String line: lines) {
System.out.println(line);
if (line.startsWith("rect")) {
Matcher matcher = pattern1.matcher(line);
matcher.find();
grid.rect(matcher.group(1), matcher.group(2));
} else {
Matcher matcher = pattern2.matcher(line);
matcher.find();
if (line.startsWith("rotate row")) {
grid.rotRow(matcher.group(1), matcher.group(2));
} else if (line.startsWith("rotate column")) {
grid.rotCol(matcher.group(1), matcher.group(2));
} else {
throw new Exception ("huh?!");
}
}
grid.print();
}
}
}