Skip to content

Instantly share code, notes, and snippets.

@joshrotenberg
Created June 27, 2019 18:53
Show Gist options
  • Save joshrotenberg/3f31fc33205e5acd3a0d9e066ddfd171 to your computer and use it in GitHub Desktop.
Save joshrotenberg/3f31fc33205e5acd3a0d9e066ddfd171 to your computer and use it in GitHub Desktop.
import kotlin.math.absoluteValue
fun diagonalDifference(arr: Array<Array<Int>>) = arr
.mapIndexed { index, ints -> Pair(ints[index], ints[arr.size - index - 1]) }
.reduce { pair, acc -> Pair(pair.first + acc.first, pair.second + acc.second) }
.let { pair -> pair.first - pair.second }
.absoluteValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment