Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created April 25, 2016 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7e8669de9b03369d743cb52e23dbeff9 to your computer and use it in GitHub Desktop.
Save anonymous/7e8669de9b03369d743cb52e23dbeff9 to your computer and use it in GitHub Desktop.
def gap(g, inf, sup, gen = nil)
gen = prime_range(inf, sup) if gen.nil?
recent = gen.next
current = gen.next
return [recent, current] if current - recent == g
gap(g, inf, sup, gen)
end
def prime_range(inf, sup)
Enumerator.new do |enum|
while inf < sup
enum.yield inf if Prime.prime? inf
inf += 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment