Skip to content

Instantly share code, notes, and snippets.

@rcanand

rcanand/goldbach.py

Created Jun 5, 2017
Embed
What would you like to do?
from sympy import sieve
def goldbach():
'''
For each even number > 2,
it finds a pair of two primes that add up to the number
'''
even = 4
while(True):
printed = False
if sieve._list[-1] < even:
sieve.extend(even * 2)
for a in sieve._list:
for b in sieve._list:
if a + b == even:
print('{} = {} + {}'.format(even, a, b))
even += 2
printed = True
break
if printed:
break
if not printed:
print('{} is a counterexample!'.format(even))
break
if __name__ == '__main__':
goldbach()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment