-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay03Lobby.kt
More file actions
25 lines (20 loc) · 981 Bytes
/
Day03Lobby.kt
File metadata and controls
25 lines (20 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package adventofcode.year2025
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day03Lobby(
customInput: PuzzleInput? = null,
) : Puzzle(customInput) {
private fun parseInput(): List<List<IndexedValue<Int>>> = input.lines().map { bank -> bank.map(Char::digitToInt).withIndex().toList() }
private fun List<List<IndexedValue<Int>>>.totalOutputJoltage(batteryCount: Int) =
sumOf { bank ->
(batteryCount downTo 1)
.fold(Triple(0, bank.size - batteryCount, 0L)) { (lIndex, rIndex, joltage), battery ->
bank
.subList(lIndex, rIndex + 1)
.maxBy { battery -> battery.value }
.let { max -> Triple(max.index + 1, bank.size - battery + 1, joltage * 10 + max.value) }
}.third
}
override fun partOne() = parseInput().totalOutputJoltage(2)
override fun partTwo() = parseInput().totalOutputJoltage(12)
}