Skip to content

Instantly share code, notes, and snippets.

@micaiahparker
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micaiahparker/9e6c081062fd12758b38 to your computer and use it in GitHub Desktop.
Save micaiahparker/9e6c081062fd12758b38 to your computer and use it in GitHub Desktop.
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
"""
@jseger
Copy link

jseger commented Jun 24, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment