Created
September 6, 2012 11:47
-
-
Save antimon2/3655342 to your computer and use it in GitHub Desktop.
Project Euler 46
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' | |
| 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