This commit is contained in:
Paul-Henri Froidmont 2025-12-01 19:07:58 +01:00
parent 69ab59a51d
commit 089c7f34db
Signed by: phfroidmont
GPG key ID: BE948AFD7E7873BE
2 changed files with 4573 additions and 2 deletions

View file

@ -9,6 +9,34 @@ val dayNumber = "01"
@main def part2: Unit =
println(part2(loadInput(dayNumber)))
def part1(input: String): String = ""
def part1(input: String): String =
case class Dial(pos: Int = 50, zeroCount: Int = 0):
def move(rot: Int): Dial =
val newPos = (pos + rot) % 100
Dial(newPos, zeroCount + (if newPos == 0 then 1 else 0))
def part2(input: String): String = ""
input
.split('\n')
.map {
case s"L$rot" => -rot.toInt
case s"R$rot" => rot.toInt
}
.foldLeft(Dial())(_.move(_))
.zeroCount.toString
def part2(input: String): String =
case class Dial(pos: Int = 50, zeroCount: Int = 0):
def move(rot: Int): Dial =
val newPos = pos + rot
val signChanged = (pos > 0 && newPos <= 0) || (pos < 0 && newPos >= 0)
val zeroPasses = Math.abs(newPos / 100) + (if signChanged then 1 else 0)
Dial(newPos % 100, zeroCount + zeroPasses)
input
.split('\n')
.map {
case s"L$rot" => -rot.toInt
case s"R$rot" => rot.toInt
}
.foldLeft(Dial())(_.move(_))
.zeroCount.toString