Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * We declare a package-level function main which returns Unit and takes
- * an Array of strings as a parameter. Note that semicolons are optional.
- */
- data class Cell(val x: Int, val y: Int, var value: Int)
- data class Action(val x: Int, val y: Int, val offsetX: Int, val offsetY: Int)
- fun action(arr: List<List<Cell>>, action: Action) {
- arr
- .slice(action.x-action.offsetX..action.x+action.offsetX)
- .forEach { row ->
- row
- .slice(action.y-action.offsetY..action.y+action.offsetY)
- .forEach { it.value += if (it.value != 0) 1 else 0 }
- }
- val targetCell = arr[action.x][action.y]
- targetCell.value -= if (targetCell.value != 1) 2 else 0
- }
- fun main() {
- // generate array
- var arr = (0..10).map {
- x -> (0..5).map {
- y -> Cell(x, y, 10)
- }
- }
- action(arr, Action(3,3,2,1))
- // print with new lines
- arr.forEach { println(it) }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement