Last active
December 22, 2015 03:19
-
-
Save pmgupte/6409805 to your computer and use it in GitHub Desktop.
My PHP solution to Project Euler problem # 1 http://projecteuler.net/problem=1 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.
Find the sum of all the multiples of 3 or 5 below 1000.
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
<?php | |
$sum = 0; | |
for ($i = 0; $i < 1000; $i++) { | |
if (!($i % 3) || !($i % 5)) { | |
$sum += $i; | |
} | |
} | |
echo $sum; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code in revision 9a8e4d24c7a9df5cbd8f6b7794fd521f55269585 took 0.0017611980438232 seconds to finish.
whereas, code in revision de495615e1f9741a39e00bf4ee5cc88d6360c880 took only 0.00026798248291016 to finish.