Skip to content

Instantly share code, notes, and snippets.

@rcanand
Created June 5, 2017 16:27
Show Gist options
  • Save rcanand/9bdbd6c60c306e4f73cd6823b0f59699 to your computer and use it in GitHub Desktop.
Save rcanand/9bdbd6c60c306e4f73cd6823b0f59699 to your computer and use it in GitHub Desktop.
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