RSS FEED

Project Euler: Problem 1

Okay, let's start with a really easy one, the first problem:
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.
The solution is pretty straightforward and doesn't require much of explanation, simply iterate over the numbers in the range and add those that meet the criteria. Done.
(
    local result = 0
    for i = 3 to 999 where mod i 3 == 0 OR mod i 5 == 0 do
        result += i
    result
)
It might be tempting to go right to the next problem but there's enough time for that, I don't plan on writing about more than one Euler problem a day, however simple it might be. Anyway, I promise I'll get back to other problems soon.

DISCLAIMER: All scripts and snippets are provided as is under Creative Commons Zero (public domain, no restrictions) license. The author and this blog cannot be held liable for any loss caused as a result of inaccuracy or error within these web pages. Use at your own risk.

This Post needs Your Comment!

Return to top