Created
June 23, 2014 11:43
-
-
Save mario/b8f8893b8eeb63cb1dc2 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
<?php | |
$A = array( | |
72, 79, 84, 46, 14, 4, 62, 88, 58, 21, 16, 27, 13, 52, 96, 70, 28, 75, | |
76, 45, 5, 71, 43, 87, 64, 95, 72, 22, 43, 15, 25, 70, 64, 93, 56, 90, | |
84, 31, 49, 71, 29, 46, 6, 17, 81, 21, 75, 44, 2, 45, 67, 57, 93, 72, | |
39, 74, 43, 53, 40, 45, 87, 23, 44, 52, 1, 56, 32, 26, 32, 67, 41 | |
); | |
$B = array(); | |
$C = array(); | |
rsort($A); | |
for($i = 0; $i<count($A); $i++) { | |
if (array_sum($B) <= array_sum($C)){ | |
array_push($B, $A[$i]); | |
} else { | |
array_push($C, $A[$i]); | |
} | |
} | |
print_r($B); | |
print_r($C); | |
printf("Sum of first is %d\n", array_sum($B)); | |
printf("Sum of second is %d\n", array_sum($C)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment