svmartin
9/16/2016 - 9:57 PM

primes_gap.rb

require 'prime'

def gap(gap, low, high)
  primes_between(low,high).each_cons(2).find { |(a,b)| b-a == gap }
end

def primes_between(low,high)
  Prime.each(high).select { |prime| prime >= low }
end


p gap(4,100,110) == [103, 107]
p gap(4,100,110)
p gap(10,300,400) == [337, 347]
p gap(10,300,400)