Last active
March 29, 2017 06:41
-
-
Save lexnjugz/7a88282c2b54275089e114ea8260bcd3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function super_sum($A){ | |
$sum = 0; | |
foreach ($A as $key => $value){ | |
//$sum += $value; | |
do { | |
$sum += $value % 10; | |
} while ($value = (int) $value / 10); | |
} | |
return $sum; | |
} | |
$A = [120, 13, 45]; | |
print_r(super_sum($A)); |
Hi Nandaa,
I think understood it all wrong. I thought it was adding individual values in array. Let me update it right now, now that I understand it better.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will this code sum up the digits really? i.e.
1 + 2 + 0 + 1 + 3 + 4 + 5
for$A = [120, 13, 34]
?