day 1 part 1

This commit is contained in:
Araozu 2023-10-31 20:57:58 -05:00
parent 4652ca7a45
commit a6f758277f

View File

@ -1,5 +1,6 @@
import scala.util.Failure import scala.util.Failure
import scala.util.Success import scala.util.Success
import scala.util.Try
object Day01 extends Solution: object Day01 extends Solution:
override def part_01() = override def part_01() =
@ -8,7 +9,20 @@ object Day01 extends Solution:
case Failure(ex) => case Failure(ex) =>
return "Error opening file: " + ex.getMessage() return "Error opening file: " + ex.getMessage()
"part 1 :D" var max_calories_amount = 0
var current_sum = 0
for line <- file.getLines() do
Try(line.toInt).toOption match
case Some(value) => current_sum += value
case None =>
if current_sum > max_calories_amount then
max_calories_amount = current_sum
current_sum = 0
max_calories_amount.toString()
override def part_02() = override def part_02() =
"part 2 :O" "part 2 :O"