Commit 21186ede authored by Taddeus Kroes's avatar Taddeus Kroes

Moved some common functions to 'utils'

parent 4a07d490
def _gcd(a, b):
while b:
a, b = b, a % b
return a
def gcd(*args):
return reduce(_gcd, args)
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import division from __future__ import division
from primes import is_prime, nprimes from utils import is_prime, nprimes
print list(nprimes(15499)) print list(nprimes(15499))
import sys; sys.exit() import sys; sys.exit()
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import division from __future__ import division
from itertools import combinations, permutations from itertools import combinations, permutations
from frac import gcd from utils import gcd
nrs = [(i, str(i)) for i in xrange(10, 100)] nrs = [(i, str(i)) for i in xrange(10, 100)]
pairs = ((0, 0), (0, 1), (1, 0), (1, 1)) pairs = ((0, 0), (0, 1), (1, 0), (1, 1))
......
#!/usr/bin/env python #!/usr/bin/env python
def is_prime(n): from utils import is_prime
if n == 2:
return True
if n < 2 or not n & 1: from itertools import permutations
return False
for i in xrange(3, int(n ** .5) + 1, 2): m = 0
if not divmod(n, i)[1]:
return False
return True for i in xrange(2, 10):
for digits in permutations(map(str, range(i, 0, -1))):
n = int(''.join(digits))
if __name__ == '__main__': if n > m and is_prime(n):
from itertools import permutations m = n
m = 0 print m
for i in xrange(2, 10):
for digits in permutations(map(str, range(i, 0, -1))):
n = int(''.join(digits))
if n > m and is_prime(n):
m = n
print m
def _gcd(a, b):
while b:
a, b = b, a % b
return a
def gcd(*args):
return reduce(_gcd, args)
def is_prime(n): def is_prime(n):
if n == 2: if n == 2:
return True return True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment