Last active
January 5, 2019 22:43
-
-
Save gavinsykes/a0b806cb05c378bc309b2eb9bf27c12d 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 | |
function euler_1($n) { | |
$result = 0; | |
$x = $n/3; | |
$y = $n/5; | |
for ($i = 1;$i<$x;$i++) { | |
$result += 3 * $i; | |
} | |
for ($i = 1;$i<$y;$i++) { | |
// If statement to make sure we haven't already added the number as a multiple of 3 | |
if (!(5*$i % 3 == 0)) { | |
$result += 5 * $i; | |
} | |
} | |
return $result; | |
} | |
echo euler_1(1000); // Returns 233168 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment