-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day01.java
51 lines (44 loc) · 1.33 KB
/
Day01.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
//package org.mrbadaxe.AdventOfCode2022;
import java.util.ArrayList;
import java.util.List;
public class Day01{
public static ArrayList<Integer> generateElfCalorieCountsList(List<String> lines){
ArrayList<Integer> elfCalorieCounts = new ArrayList<Integer>();
int nextCalorieCount = 0;
for(String line : lines){
if(line.equals("")){
elfCalorieCounts.add(nextCalorieCount);
nextCalorieCount = 0;
}else{
nextCalorieCount += Integer.parseInt(line);
}
}
return elfCalorieCounts;
}
public static int getPart01(List<String> input){
ArrayList<Integer> elfCalorieCounts = generateElfCalorieCountsList(input);
int maxCalorieCount = 0;
for(Integer i : elfCalorieCounts){
maxCalorieCount = (i > maxCalorieCount) ? i : maxCalorieCount;
}
return maxCalorieCount;
}
public static int getPart02(List<String> input){
ArrayList<Integer> elfCalorieCounts = generateElfCalorieCountsList(input);
int[] top3 = {0,0,0};
for(Integer i : elfCalorieCounts){
top3[2] = (i > top3[2]) ? i : top3[2];
if(top3[2] > top3[1]){
int x = top3[1];
top3[1] = top3[2];
top3[2] = x;
}
if(top3[1] > top3[0]){
int x = top3[0];
top3[0] = top3[1];
top3[1] = x;
}
}
return top3[0]+top3[1]+top3[2];
}
}