Skip to content

Instantly share code, notes, and snippets.

@liango2
Created January 14, 2016 18:29
Show Gist options
  • Save liango2/63cd4443a60361ec140c to your computer and use it in GitHub Desktop.
Save liango2/63cd4443a60361ec140c to your computer and use it in GitHub Desktop.
DiagonalDifference
object Solution {
def main(args: Array[String]) {
val sc = new java.util.Scanner(System.in);
var n = sc.nextInt();
var a = Array.ofDim[Int](n, n);
for (a_i <- 0 to n - 1) {
for (a_j <- 0 to n - 1) {
a(a_i)(a_j) = sc.nextInt();
}
}
val v1 = (for (i <- 0 to n - 1; j <- 0 to n - 1 if i == j) yield a(i)(j)).sum
val v2 = (for (i <- 0 to n - 1; j <- n-1 to 0 by -1 if i + j == n - 1) yield a(i)(j)).sum
println(math.abs(v1 - v2))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment