-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay1.java
More file actions
45 lines (41 loc) · 998 Bytes
/
Day1.java
File metadata and controls
45 lines (41 loc) · 998 Bytes
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
import java.util.ArrayList;
import java.util.Collections;
public class Day1 {
public static void main(String[] args) {
new Day1();
}
public Day1() {
ArrayList<String> input = ReadInput.read("res/input1.txt");
partOne(input);
partTwo(input);
}
private void partOne(ArrayList<String> input) {
int highestCalCount = -1;
int counter = 0;
for(String s : input) {
if(s.equals("")) {
if(counter > highestCalCount)
highestCalCount = counter;
counter = 0;
continue;
}
counter += Integer.parseInt(s);
}
System.out.println(highestCalCount);
}
private void partTwo(ArrayList<String> input) {
ArrayList<Integer> calList = new ArrayList<Integer>();
int counter = 0;
for(String s : input) {
if(s.equals("")) {
calList.add(counter);
counter = 0;
continue;
}
counter += Integer.parseInt(s);
}
Collections.sort(calList);
Collections.reverse(calList);
System.out.println(calList.get(0) + calList.get(1) + calList.get(2));
}
}