Created
September 7, 2012 09:12
-
-
Save antimon2/3664529 to your computer and use it in GitHub Desktop.
Project Euler 47
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_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