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
from __future__ import division
from primes import is_prime, nprimes
from utils import is_prime, nprimes
print list(nprimes(15499))
import sys; sys.exit()
......
#!/usr/bin/env python
from __future__ import division
from itertools import combinations, permutations
from frac import gcd
from utils import gcd
nrs = [(i, str(i)) for i in xrange(10, 100)]
pairs = ((0, 0), (0, 1), (1, 0), (1, 1))
......
#!/usr/bin/env python
def is_prime(n):
if n == 2:
return True
from utils import is_prime
if n < 2 or not n & 1:
return False
from itertools import permutations
for i in xrange(3, int(n ** .5) + 1, 2):
if not divmod(n, i)[1]:
return False
m = 0
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__':
from itertools import permutations
if n > m and is_prime(n):
m = n
m = 0
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
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):
if n == 2:
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