From d8f1d27bd745808784baed72582fbef844f0dd8d Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Thu, 1 Dec 2022 21:38:31 +1030 Subject: [PATCH] Playing around with Scala --- 2022/day1-v2.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 2022/day1-v2.scala diff --git a/2022/day1-v2.scala b/2022/day1-v2.scala new file mode 100644 index 0000000..af09300 --- /dev/null +++ b/2022/day1-v2.scala @@ -0,0 +1,11 @@ +import scala.collection.mutable.ArrayBuffer +import scala.io.Source + +@main def main() = + val elfRations = Source.fromFile("day1-input").mkString.split("\n\n").map(_.split("\n").map(_.toInt)) + val sortedElfCalories = elfRations.map(_.sum).sorted + + // Part 1 solution: Total calories held by elf with the most total calories + println(s"${sortedElfCalories.last}") + // Part 2 solution: Total calories held by the top 3 elves + println(s"${sortedElfCalories.takeRight(3).sum}")