Created
June 27, 2019 18:53
-
-
Save joshrotenberg/3f31fc33205e5acd3a0d9e066ddfd171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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