Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Last active January 5, 2019 22:43
Show Gist options
  • Save gavinsykes/a0b806cb05c378bc309b2eb9bf27c12d to your computer and use it in GitHub Desktop.
Save gavinsykes/a0b806cb05c378bc309b2eb9bf27c12d to your computer and use it in GitHub Desktop.
<?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