Last active
November 28, 2018 14:30
-
-
Save wware/265e21a8a5a2afb325b265bfd119dee9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
https://twitter.com/fermatslibrary/status/1067423316095508480 | |
Today's paper is a good example of an unsolved conjecture being disproved by counterexample. | |
Goldbach stated that every positive odd integer is either prime or the sum of a prime and | |
twice a square. 5777 and 5993 are the only known counterexamples. | |
https://fermatslibrary.com/s/a-not-so-famous-goldbach-conjecture#email-newsletter | |
""" | |
# this is python 2, not python3 | |
import sys | |
primes = [2, 3, 5, 7] | |
def test_primality(n): | |
m = primes[-1] + 2 | |
while m ** 2 <= n: | |
if test_primality(m): | |
primes.append(m) | |
m += 2 | |
for k in primes: | |
if (n % k) == 0: | |
return False | |
if k ** 2 > n: | |
break | |
return True | |
def test_goldbach(n): | |
test_primality((n + 1) ** 2) | |
if n in primes: | |
return True | |
for p in primes: | |
if p >= n: | |
break | |
diff = n - p | |
halfdiff = 0.5 * diff | |
sqrthalfdiff = halfdiff ** 0.5 | |
if sqrthalfdiff == int(sqrthalfdiff): | |
return True | |
return False | |
max = 10000 | |
if len(sys.argv) > 1: | |
max = int(sys.argv[1]) | |
for i in range(3, max, 2): | |
try: | |
if not test_goldbach(i): | |
print i | |
except KeyboardInterrupt: | |
print "Got as far as", i | |
raise SystemExit | |
""" | |
Running this code => 5777, 5993 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment