Skip to content

Instantly share code, notes, and snippets.

@antimon2
Created September 6, 2012 11:47
Show Gist options
  • Select an option

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

Select an option

Save antimon2/3655342 to your computer and use it in GitHub Desktop.
Project Euler 46
require 'prime'
def project_euler_46
Prime.each_cons(2) do |p1, p2|
(p1 + 2).step(p2 - 2, 2) do |n|
return n unless (1..Math.sqrt((n-3)/2)).find{|m|(q = n - 2*m*m).prime?}
end
end
end
if $0 == __FILE__
p project_euler_46
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment