Last active
August 29, 2015 14:23
-
-
Save micaiahparker/9e6c081062fd12758b38 to your computer and use it in GitHub Desktop.
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 is_prime_short(number): | |
return number == 2 or number > 1 and number % 2 != 0 and not any(i for i in range(3, int(math.sqrt(number)+1), 2) if number % i == 0) | |
""" | |
Its actually pretty simple | |
First - if its 1 or less - false | |
Second - if its 2 - true | |
Third - if its even - false | |
Fourth - the speedy meat - check between 3 and the square root of the number you want rounded up + 1 and only check odd numbers. | |
if the number you are checking is divisible by (i) you are not prime - false | |
Fifth - True | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/jseger/c9b74e93b622559faa5c