Day 1
This commit is contained in:
commit
bfd82a5476
9 changed files with 2390 additions and 0 deletions
23
aoc/src/Day1.scala
Normal file
23
aoc/src/Day1.scala
Normal 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}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue