Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
def prime(a):
|
||||
return not (a < 2 or any(a % x == 0 for x in xrange(2, int(a**0.5) + 1)))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def prime2(a):
|
||||
if a == 2: return True
|
||||
if a < 2 or a % 2 == 0: return False
|
||||
return not any(a % x == 0 for x in xrange(3, int(a**0.5) + 1, 2))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
def prime3(a):
|
||||
if a < 2: return False
|
||||
if a == 2 or a == 3: return True # manually test 2 and 3
|
||||
if a % 2 == 0 or a % 3 == 0: return False # exclude multiples of 2 and 3
|
||||
|
||||
maxDivisor = a**0.5
|
||||
d, i = 5, 2
|
||||
while d <= maxDivisor:
|
||||
if a % d == 0: return False
|
||||
d += i
|
||||
i = 6 - i # this modifies 2 into 4 and viceversa
|
||||
|
||||
return True
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
>>> import re
|
||||
>>> def isprime(n):
|
||||
return not re.match(r'^1?$|^(11+?)\1+$', '1' * n)
|
||||
|
||||
>>> # A quick test
|
||||
>>> [i for i in range(40) if isprime(i)]
|
||||
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
|
||||
Loading…
Add table
Add a link
Reference in a new issue