Created
March 29, 2018 09:19
-
-
Save phpfiddle/b1412fb265c97b57aa8f710ba51714f8 to your computer and use it in GitHub Desktop.
[ Posted by Michaeljpitz ] Multiples of 3 or 5 PHP Codewars
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 | |
// Multiples of 3 or 5 PHP | |
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. | |
// Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. | |
function solution($number) { | |
$tot = 0; | |
for ($i = 3; $i < $number; $i++) if ($i % 3 === 0 || $i % 5 === 0) $tot += $i; | |
return $tot; | |
} | |
echo solution(10);//23 | |
echo "<hr>"; | |
echo solution(20);//... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment