Day 1
This commit is contained in:
parent
69ab59a51d
commit
089c7f34db
2 changed files with 4573 additions and 2 deletions
4543
input/day01
Normal file
4543
input/day01
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -9,6 +9,34 @@ val dayNumber = "01"
|
||||||
@main def part2: Unit =
|
@main def part2: Unit =
|
||||||
println(part2(loadInput(dayNumber)))
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue