Created
March 18, 2011 23:01
-
-
Save gdemir/877005 to your computer and use it in GitHub Desktop.
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 | |
| #-*-coding:utf-8-*- | |
| # Find the sum of all the multiples of 3 or 5 below 1000. | |
| print sum(i for i in range(1000) if i % 3 == 0 or i % 5 == 0) |
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 | |
| #-*-coding:utf-8-*- | |
| # What is the 10001st prime number? | |
| def prime_n(max): | |
| primes = [] | |
| n = 2 | |
| while True: | |
| prime = True | |
| for i in range(2, n): | |
| if n % i == 0: prime = False; break | |
| if prime: primes.append(n) | |
| if len(primes) == max: return primes | |
| n = n + 1 | |
| print prime_n(10001)[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment