diff --git a/2022/day01/RankedCalorieCount.java b/2022/day01/RankedCalorieCount.java new file mode 100644 index 0000000..7739637 --- /dev/null +++ b/2022/day01/RankedCalorieCount.java @@ -0,0 +1,32 @@ +import java.nio.file.Paths; +import java.io.IOException; +import java.util.Scanner; +import java.util.ArrayList; +import java.util.Collections; + +public class RankedCalorieCount { + public static void main (String[] args) { + try (Scanner inputReader = new Scanner(Paths.get("input.txt"))) { + ArrayList calsList = new ArrayList(); + while (inputReader.hasNext()) { + int currentCals = 0; + String inLine = new String(); + do { + inLine = inputReader.nextLine(); + if (!inLine.isEmpty()) { + currentCals += Integer.parseInt(inLine); + } + } while (!inLine.isEmpty() && inputReader.hasNext()); + calsList.add(currentCals); + } + + Collections.sort(calsList); + Collections.reverse(calsList); + int topThreeSum = calsList.get(0)+calsList.get(1)+calsList.get(2); + System.out.printf("The sum of calories by the top three is: %d%n", topThreeSum); + } catch (IOException e) { + System.out.println("IOException"); + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/2022/day01/day01_algo.docx b/2022/day01/day01_algo.docx index 4d37158..18f4c96 100644 Binary files a/2022/day01/day01_algo.docx and b/2022/day01/day01_algo.docx differ