Project Euler is a series of programming challenges (https://projecteuler.net)
This is problem #1 in the series.

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 problem can be easily solved in a single python line, but that involves looping over all numbers from 0-1000 and checking if they're a multiple of 3 or 5 via modulo.

Here is an example of solving the problem without looping over every possible number, only performing 466 cycles instead of 1000

```
# 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.
def euler_1():
# vars to track our multiples
multiples = []
# have we counted all the multiples in range yet?
mot_counted = False
mof_counted = False
# counter for finding multiples
counter = 1
# loop forever (until we break the loop)
while True:
# get multiples
mot = 3 * counter
mof = 5 * counter
# is our multiple below 1000?
if mot < 1000:
# add multiple to our list
if mot not in multiples:
multiples.append(mot)
else:
# we've reached all the multiples of 3 under 1000
mot_counted = True
# if our second multiple is below 1000
# and already not in our list of multiples
if mof < 1000:
if mof not in multiples:
# add multiple to our list
multiples.append(mof)
else:
# we've reached all the multiples of 5 under 1000
mof_counted = True
if mof_counted and mot_counted:
break
else:
# increase our counter and continue
counter += 1
print("Found {} total multiples.".format(len(multiples)))
print("Sum: {}".format(sum(multiples)))
if __name__ == "__main__":
euler_1()
```

## Sort: Top

[–] RevanProdigalKnight 0 points 1 points 1 points (+1|-0) ago (edited ago)

Your euler function could still be made more deterministic and shorter than it is.

This finds the same answer in only 334 iterations

[–] RevanProdigalKnight 0 points 0 points 0 points (+0|-0) ago (edited ago)

Equivalent JS code that I used to figure out the method beforehand (because my Python is a bit rusty):

[–] peacegnome 0 points 0 points 0 points (+0|-0) ago

Less clear, but could be done with math. I might write it out later but basically "1000/3/5" is key

[–] omacu 0 points 0 points 0 points (+0|-0) ago

Nice post

[–] rcb 1 points -1 points 0 points (+0|-1) ago (edited ago)

Couldn't you do this?

EDIT Turns out you have to use

`//`

for integer division. Keep missing that!Oh, sum not count... In that case

[–] Satirical [S] 0 points 0 points 0 points (+0|-0) ago

Ooh, triangle numbers. Clever.