diff options
Diffstat (limited to 'aoc-2021-kotlin/src/Utils.kt')
-rw-r--r-- | aoc-2021-kotlin/src/Utils.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/aoc-2021-kotlin/src/Utils.kt b/aoc-2021-kotlin/src/Utils.kt index 4f78a1f..2be34ac 100644 --- a/aoc-2021-kotlin/src/Utils.kt +++ b/aoc-2021-kotlin/src/Utils.kt @@ -26,6 +26,24 @@ data class Pos2D(val x: Int, val y: Int) { operator fun minus(other: Pos2D) = Pos2D(x - other.x, y - other.y) } +data class Pos3D(val x: Int, val y: Int, val z: Int) { + companion object { + val zero = Pos3D(0, 0, 0) + val unique = Pos3D(1, 2, 3) + + fun fromString(string: String) = string + .split(",") + .map(String::toInt) + .let { Pos3D(it[0], it[1], it[2]) } + } + + operator fun unaryMinus() = Pos3D(-x, -y, -z) + + operator fun plus(other: Pos3D) = Pos3D(x + other.x, y + other.y, z + other.z) + + operator fun minus(other: Pos3D) = Pos3D(x - other.x, y - other.y, z - other.z) +} + fun parseToMap(input: List<String>): Map<Pos2D, Int> = input.flatMapIndexed { y, line -> line.mapIndexed { x, char -> |