This commit is contained in:
Paul-Henri Froidmont 2022-12-02 16:48:27 +01:00
commit bfd82a5476
Signed by: phfroidmont
GPG key ID: BE948AFD7E7873BE
9 changed files with 2390 additions and 0 deletions

2253
aoc/resources/day1Input.txt Normal file

File diff suppressed because it is too large Load diff

23
aoc/src/Day1.scala Normal file
View file

@ -0,0 +1,23 @@
import scala.io.Source
object Day1 extends App:
val calories = Source
.fromURL(getClass.getResource("day1Input.txt"))
.mkString
.split('\n')
.toList
val elvesCalories = calories
.foldLeft(List(0)) {
case (elvesTotal, caloriesValue) if caloriesValue.isEmpty =>
0 :: elvesTotal
case (elfTotal :: elveTotal, caloriesValue) =>
caloriesValue.toInt + elfTotal :: elveTotal
}
println(s"Part 1: ${elvesCalories.max}")
val top3ElvesCalories = elvesCalories.sorted.takeRight(3).sum
println(s"Part 2: ${top3ElvesCalories}")