- Spoiler Alert -

If you have any interest in solving any of these problems at Project Euler, quit reading this post and immediately pull up your programming editor of choice and have at it.

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.

$result = 0

for($i = 0; $i -lt 1000;$i++)

{

if ($i % 3 -eq 0 -or $i % 5 -eq 0)

{

$result += $i;

}

}

$result

## 3 comments:

Good stuff. Another way to skin the cat.

1..999 |

Where {$_ % 3 -eq 0 -or $_ % 5 -eq 0} |

ForEach {$sum=0} {$sum+=$_} {$sum}

Gotta love the one-liners! Thanks Doug!

Rip Blu-ray for Macwith Blu-ray Ripper for Mac, snow Leopard included.- Free Download and have a try.Ultimate

Blu-ray video converteris actually an 3-in-one software including Blu-ray Ripper, DVD Ripper and Video Converter.Blu-ray ripperenables you directly rip and convert your Blu-ray movies and general DVDs, even the protected DVDs and Blu-ray DVDs into other popular audio and video formats.Post a Comment