I stayed so close to the code posted by <@U7V8BA8R...
# advent-of-code
j
I stayed so close to the code posted by @Pavlo Liapota it is straight-up plagiarism, so no need to post it. 🙂 Today's timings (first/best of 25 in ms): JVM
256/19
, JS
316/130
, native
649/393
I did discover something useful today - you can have more than one
operator fun get
and
set
implementation in a single class. So for today, I wrapped an
val grid: Array<Array<Soil>>
in a class, and defined the following methods:
Copy code
operator fun get(pos: Position) = grid[pos.x][pos.y]

operator fun get(x: Int, y: Int) = grid[x][y]

operator fun set(x: Int, y: Int, type: Soil) {
    grid[x][y] = type
}

operator fun set(pos: Position, type: Soil) {
    grid[pos.x][pos.y] = type
}
so I can use both
world[x, y]
and
world[pos]
at my convenience (and do some bounds checking not shown above)
💡 1