Skip to content

Instantly share code, notes, and snippets.

@antimon2
Created September 7, 2012 09:12
Show Gist options
  • Select an option

  • Save antimon2/3664529 to your computer and use it in GitHub Desktop.

Select an option

Save antimon2/3664529 to your computer and use it in GitHub Desktop.
Project Euler 47
require 'prime'
def project_euler_47 n=4
return if n < 2
Prime.each_cons(2) do |p1, p2|
nums = ((p1+1)...p2).select{|m|m.prime_division.size==n}
idx = 0.upto(nums.size-n).find{|i|nums[i+n-1]==nums[i]+n-1}
return nums[idx] if idx
end
end
if $0 == __FILE__
p project_euler_47
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment