Created
February 12, 2016 07:27
-
-
Save ken-master/24ec01a33575bc9709fa to your computer and use it in GitHub Desktop.
diagonal array summation
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
<?php | |
$handle = fopen ("php://stdin","r"); | |
fscanf($handle,"%d",$n); | |
$a = array(); | |
for($a_i = 0; $a_i < $n; $a_i++) { | |
$a_temp = fgets($handle); | |
$a[] = explode(" ",$a_temp); | |
array_walk($a[$a_i],'intval'); | |
} | |
$left[0] = array_sum( | |
array_map(function($row, $index){ | |
return $row[$index]; | |
}, $a, array_keys($a) | |
) | |
); | |
$right[1] = array_sum( array_map(function($row, $index){ | |
return $row[$index]; | |
}, $a, array_reverse(array_keys($a))) ); | |
$result = array_diff($right, $left); | |
print_r($result); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment