This file contains 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
Show hidden characters
# Get Sublime Text to use your rvm ruby without hardcoding a `$USER`. | |
# | |
# Include the configurations below the commend in the appropriate file listed below: | |
# | |
# - OS X ST2: ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.sublime-build | |
# - OS X ST3: ~/Library/Application Support/Sublime Text 3/Packages/User/Ruby.sublime-build | |
# - Linux ST2: ~/.config/sublime-text-2/Packages/Ruby/Ruby.sublime-build | |
# - Linux ST3: ~/.config/sublime-text-3/Packages/User/Ruby.sublime-build | |
{ |
This file contains 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
def self.prime?(num) | |
return num > 1 if num <= 3 | |
return false if (divisible?(num,2) || divisible?(num,3)) | |
# loop while (6*k-1)**2 <= num, or | |
# k <= (1+sqrt(num)/6) | |
max_k = (Math.sqrt(num)+1)/6.0 | |
return false if (1..max_k).any? {|k| divisible?(num,6*k+1) || divisible?(num,6*k-1)} | |
end |
This file contains 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
class Prime | |
include Enumerable | |
def self.nth(index) | |
raise ArgumentError, 'index out of bound' if index <= 0 | |
new.take(index).last | |
end | |
def each(&block) | |
(2..Float::INFINITY).each do |i| |
NewerOlder