Last active
December 23, 2015 03:29
-
-
Save jonelf/6573557 to your computer and use it in GitHub Desktop.
It's currently unknown if this program will ever halt.
http://en.wikipedia.org/wiki/Goldbach's_conjecture
http://en.wikipedia.org/wiki/Halting_problem
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
require 'prime' | |
primes = Prime.lazy | |
n = 4 | |
loop do | |
n += 2 | |
prime1 = primes.next | |
prime2 = n - 1 | |
prime2 -= 2 until prime2.prime? | |
while n != prime1 + prime2 | |
prime1 = primes.next | |
if prime1 + prime2 > n | |
prime1 = primes.rewind.next | |
prime2 -= 2 | |
prime2 -= 2 until prime2.prime? | |
abort "The Goldbach Conjecture is false!" if prime2 < n/2 | |
end | |
end | |
puts "#{n} = #{prime1} + #{prime2}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment