Skip to content

Instantly share code, notes, and snippets.

View KevinWMatthews's full-sized avatar
🦀
Studying Rust

Kevin W Matthews KevinWMatthews

🦀
Studying Rust
View GitHub Profile
# 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
{
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
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|