Skip to content

Commit 5befb7a

Browse files
authored
Merge pull request #1 from mjl757/patch-1
Add row col based get to Grid2D.kt
2 parents 6cf39cc + 37bee39 commit 5befb7a

File tree

1 file changed

+3
-1
lines changed
  • src/main/kotlin/com/soberg/aoc/utlities/datastructures

1 file changed

+3
-1
lines changed

src/main/kotlin/com/soberg/aoc/utlities/datastructures/Grid2D.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ data class Grid2D<T>(
2121

2222
infix operator fun get(location: Location): T = grid[location.row][location.col]
2323

24+
operator fun get(row: Int, col: Int): T = grid[row][col]
25+
2426
/** @return true if the specified [location] is in the bounds of this grid, false if not. */
2527
fun isInBounds(location: Location): Boolean = isInBounds(location.row, location.col)
2628

@@ -127,4 +129,4 @@ fun <T> List<List<T>>.toGrid2D() = Grid2D(this)
127129
/** Converts the common AoC input (List of lines (as String) from input file). */
128130
inline fun <T> List<String>.toGrid2D(convertLine: (String) -> List<T>) = map { line ->
129131
convertLine(line)
130-
}.toGrid2D()
132+
}.toGrid2D()

0 commit comments

Comments
 (0)