Skip to content

Instantly share code, notes, and snippets.

@Tricky1975
Created October 4, 2018 08:13
Show Gist options
  • Save Tricky1975/9eda35d1edfeb881931f973ffcfbaeb5 to your computer and use it in GitHub Desktop.
Save Tricky1975/9eda35d1edfeb881931f973ffcfbaeb5 to your computer and use it in GitHub Desktop.
Goldbach thought every even number higher than 2 is the sum of two prime numbers... This Python script tries this out till 5000
m=5000
ver=[];
for i in range(0,m+1): ver.append(0)
for a in range(1,m+1):
for b in range(1,m+1):
c = a * b;
if c<=m: ver[c]+=1
primes=[]
for i in range(1,m+1):
if ver[i]==2 and (not i in primes): primes.append(i);
print primes
goldbach = [];
for i in range(0,m+1): goldbach.append(False);
for p1 in primes:
for p2 in primes:
h = p1 + p2
if h<=m and (h%2==0):
goldbach[h]=True
print "%d + %d = %d"%(p1,p2,h)
for i in range(4,len(goldbach)):
if goldbach[i]: print "Goldbach was right for: %d"%i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment