diff --git a/2024/src/main/kotlin/Grid.kt b/2024/src/main/kotlin/Grid.kt index 44bbda0..cfad170 100644 --- a/2024/src/main/kotlin/Grid.kt +++ b/2024/src/main/kotlin/Grid.kt @@ -13,23 +13,21 @@ class Grid(val rows: List) { fun chars(x: Int, y: Int, dx: Int, dy: Int) = Line(x, y, dx, dy) inner class Line(val x: Int, val y: Int, val dx: Int, val dy: Int) : Sequence { - override fun iterator(): Iterator = iterator { - if (dx == 1 && dy == 0) { - yieldAll(rows[y].substring(startIndex = x).asSequence()) - } else { + override fun iterator(): Iterator = if (dx == 1 && dy == 0) { + rows[y].substring(startIndex = x).iterator() + } else iterator { + var x = x + var y = y - var x = x - var y = y - - while (x in 0.. = sequence { for (y in 0..