2009-01-31

Project Euler: Problem 1

As part of my ongoing efforts to learn Python, I've decided to start working through the Project Euler problem sets. If you don't want to see spoilers, then leave now. Here's the Python script I whipped out for Problem One.

"""Finds the solution to Problem 1 from Project Euler.
For more details, see http://projecteuler.net/index.php?section=problems&id=1
"""
def problem_one():
"""Sum the natural numbers less than 1000 that are multiples of 3 or 5."""
return sum([n for n in range(1000) if ((0 == n % 3) or (0 == n % 5))])
if (__name__ == "__main__"):
print problem_one()
view raw problem1.py hosted with ❤ by GitHub

Back to flipping out...