-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDay1.java
43 lines (32 loc) · 870 Bytes
/
Day1.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
package aoc15;
import java.io.File;
import java.util.List;
import myutils15.StaticUtils;
public class Day1 {
private List<String> rawData;
public Day1(File input) {
rawData = StaticUtils.fileToStringList(input);
}
public int run1() {
return (int) (rawData.get(0).chars().filter(c -> c == '(').count() - rawData.get(0).chars().filter(c -> c == ')').count());
}
public int run2() {
int floor = 0;
String input = rawData.get(0);
for(int i = 0; i < input.length(); i++) {
if(input.charAt(i) == '(') {
floor++;
} else {
floor--;
}
if(floor == -1) {
return i + 1;
}
}
return -1;
}
public static void main(String[] args) {
Day1 test = new Day1(new File("C:\\Users\\Timucin\\Desktop\\Advent of code 2015\\Day 1\\InputFile1.txt"));
System.out.println(test.run2());
}
}