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.
This file contains 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
"""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() | |
Back to flipping out...