Created
April 15, 2015 03:14
-
-
Save KevinWMatthews/eea637827ae11fc3c6dc to your computer and use it in GitHub Desktop.
prime?
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 |
Oh! Just saw this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@KevinWMatthews -- will you post your updates to this, here in the gist? I'm curious to see what you come up with :D