I've tried to write a code for the weak Goldbach Conjecture, which states that every odd number greater than 5 can be expressed as the sum of three prime numbers. However, the code only returns (0, 0, 0). I only need one triple that works rather than a list of triples. Any ideas where I'm going wrong? Also I know that the code isn't the most efficient as it is, especially using the eratosthenes function to generate my primes, but this is the form that I've been asked to code in.
def eratosthenes(n):
primes = list (range(2, n+1))
for i in primes:
j=2
while i*j<= primes[-1]:
if i*j in primes:
primes.remove(i*j)
j=j+1
return primes
def weak_goldbach(N):
x, y, z = 0, 0, 0
result = 0
if not N % 2:
prime = eratosthenes(N)
while result != N:
for i in range(len(prime)):
x = prime[i]
if result == N:
break
for j in range(i, len(prime)):
y = prime[j]
result = x + y
if result == N:
break
for k in range (j, len(prime)):
z = prime[k]
result = x + y + z
if result == N:break
return x, y, z