Created
October 4, 2016 08:49
-
-
Save nvdv/5dab856fc1549f9818154a0c225fc686 to your computer and use it in GitHub Desktop.
How profilers work - prime generator
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
def is_prime(n): | |
for i in range(2, n): | |
if n % i == 0: | |
return False | |
return True | |
def sum_of_digits(n): | |
s = 0 | |
while n: | |
s += n % 10 | |
n //= 10 | |
return s | |
def get_primes(n): | |
primes = [] | |
candidate = 2 | |
while len(primes) < n: | |
if is_prime(candidate) and sum_of_digits(candidate) % 2 == 0: | |
primes.append(candidate) | |
candidate += 1 | |
return primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment