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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.