Created
March 1, 2016 17:59
-
-
Save foresmac/ce6d133e4cf5f2881e74 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
# I found this on stack overflow but I forget where. | |
def is_prime(n): | |
""""pre-condition: n is a nonnegative integer | |
post-condition: return True if n is prime and False otherwise.""" | |
if n < 2: | |
return False; | |
if n % 2 == 0: | |
return n == 2 # return False | |
k = 3 | |
while k*k <= n: | |
if n % k == 0: | |
return False | |
k += 2 | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment