Skip to content

Instantly share code, notes, and snippets.

@nvdv
Created October 4, 2016 08:49
Show Gist options
  • Save nvdv/5dab856fc1549f9818154a0c225fc686 to your computer and use it in GitHub Desktop.
Save nvdv/5dab856fc1549f9818154a0c225fc686 to your computer and use it in GitHub Desktop.
How profilers work - prime generator
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