Kotlin
I'm not fully happy with my parsing today, but oh well. I also thought about just plain building the grid and then rotating it, but "normal input parsing" works too.
Solution
class Day06 : Puzzle {
val numsPartOne = mutableListOf<MutableList<Long>>()
val numsPartTwo = mutableListOf<List<Long>>()
val ops = mutableListOf<(Long, Long) -> Long>()
override fun readFile() {
val input = readInputFromFile("src/main/resources/a2025/day06.txt")
val lines = input.lines().filter { it.isNotBlank() }
// parse part1 input
for (line in lines.dropLast(1)) {
for ((c, num) in line.trim().split(" +".toRegex()).withIndex()) {
if (numsPartOne.getOrNull(c) == null) numsPartOne.add(mutableListOf())
numsPartOne[c].add(num.toLong())
}
}
// parse part2 input
var numList = mutableListOf<Long>()
for (c in 0..<lines.maxOf { it.length }) {
var numStr = ""
for (r in 0..<lines.size - 1) {
numStr += lines[r].getOrElse(c) { ' ' }
}
if (numStr.isBlank()) {
numsPartTwo.add(numList)
numList = mutableListOf()
} else {
numList.add(numStr.trim().toLong())
}
}
numsPartTwo.add(numList)
// parse operators
ops.addAll(
lines.last().split(" +".toRegex())
.map { it.trim()[0] }
.map {
when (it) {
'*' -> { a: Long, b: Long -> a * b }
'+' -> { a: Long, b: Long -> a + b }
else -> throw IllegalArgumentException("Unknown operator: $it")
}
}
)
}
override fun solvePartOne(): String {
return numsPartOne.mapIndexed { c, list -> list.reduce { a, b -> ops[c](a, b) } }.sum().toString()
}
override fun solvePartTwo(): String {
return numsPartTwo.mapIndexed { c, list -> list.reduce { a, b -> ops[c](a, b) } }.sum().toString()
}
}
full code on Codeberg