Created
June 6, 2012 10:45
-
-
Save antimon2/2881244 to your computer and use it in GitHub Desktop.
Prime#cosins
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' | |
| class Prime | |
| def cosins n = nil | |
| return to_enum :cosins, n unless block_given? | |
| yield [3, 7] | |
| each(n).each_cons(2) do |p1, p2| | |
| yield [p1, p2] if p2 - p1 == 4 | |
| end | |
| end | |
| end | |
| # Prime.cosins.take(10) | |
| # => [[3, 7], [7, 11], [13, 17], [19, 23], [37, 41], [43, 47], [67, 71], [79, 83], [97, 101], [103, 107]] | |
| # Prime.cosins(100).to_a | |
| # => [[3, 7], [7, 11], [13, 17], [19, 23], [37, 41], [43, 47], [67, 71], [79, 83]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment