fork download
  1. <?php
  2.  
  3. function diagonalDifference($arr) {
  4. $i = 0;
  5. $n = count($arr);
  6. return abs(array_reduce($arr,
  7. function ($c, $str) use (&$i, $n ) {
  8. $i++;
  9. return $c + $str[$i-1] - $str[$n-$i];
  10. }, 0));
  11. }
  12.  
  13. print(diagonalDifference(
  14. [
  15. [11, 2, 4],
  16. [4, 5, 6],
  17. [10, 8, -12]
  18. ])); // should be 15
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
15