Skip to content

Commit

Permalink
add easy way to get chunks from input
Browse files Browse the repository at this point in the history
  • Loading branch information
derNiklaas committed Dec 15, 2024
1 parent 10f1e80 commit 2ce4999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/Day13.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import org.jetbrains.kotlinx.multik.api.ndarray
import org.jetbrains.kotlinx.multik.ndarray.operations.first
import org.jetbrains.kotlinx.multik.ndarray.operations.last
import utils.AoCDay
import utils.chunkedInput
import utils.mapInner
import utils.mapToLong

class Day13 : AoCDay() {
val splits = input.joinToString("\n").split("\n\n")
.map { it.split("\n").map { it.split(": ")[1].split(", ").map { it.drop(2) }.mapToLong() } }
val splits = input.chunkedInput()
.mapInner { it.split(": ")[1].split(", ").map { it.drop(2) }.mapToLong() }
val validDistance = 0.01

override fun part1(): Any {
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ fun Int.isEven(): Boolean {
fun Long.isEven(): Boolean {
return this % 2 == 0L
}

fun List<String>.chunkedInput(): List<List<String>> {
return this.joinToString("\n").split("\n\n").map { it.split("\n") }
}

0 comments on commit 2ce4999

Please sign in to comment.