Last active
April 26, 2017 09:25
-
-
Save rec/6b7c9b6c47e685f36f11216047af5f1d to your computer and use it in GitHub Desktop.
Which is 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
from math import sqrt | |
from itertools import count, islice | |
CANDIDATES = (15485867, 15485917, 15485927, 15485933, 15485941, | |
15485957, 15485989, 15485993, 15486013, 15486041) | |
def is_prime(n): | |
# from http://stackoverflow.com/a/27946768/43839 | |
return n > 1 and all(n % i for i in islice(count(2), int(sqrt(n) - 1))) | |
for n in CANDIDATES: | |
if not is_prime(n): | |
print(n, 'is not prime') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment