Created
March 21, 2014 20:59
-
-
Save eeeady/9696378 to your computer and use it in GitHub Desktop.
Project Euler Practice - Problem 1 (python)
This file contains hidden or 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
| #!/usr/bin/python | |
| # project euler problem 1 | |
| #all the natural numbers below 10 are multiples of 3 or 5 | |
| # 3,5,6,9 their sum is 23 | |
| # find the sum of all the multiples of 3 or 5 below 1000 | |
| limit = 1000 | |
| def main(): | |
| summandr = [] | |
| lim3 = 1 + limit / 3 | |
| lim5 = limit / 5 | |
| for i in range(1, lim3): | |
| summandr.append( i * 3 ) | |
| for i in range(1,lim5): | |
| summandr.append( i * 5) | |
| summandr = set(summandr) | |
| print sum(summandr) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment