cleaning up and organizing old problems (builtin)

This commit is contained in:
Mari Wahl 2015-01-06 20:10:48 -05:00
parent 6afe96fa4d
commit 3fdbc2a605
106 changed files with 480 additions and 1472 deletions

View file

@ -0,0 +1,37 @@
#!/usr/bin/env python
__author__ = "bt3"
'''
find prime factors of a number.
'''
import math
def find_prime_factors(n):
'''
>>> find_prime_factors(14)
[2, 7]
>>> find_prime_factors(19)
[]
'''
divisors = [d for d in range(2, n//2 + 1) if n % d == 0]
primes = [d for d in divisors if is_prime(d)]
return primes
def is_prime(n):
for j in range(2, int(math.sqrt(n))):
if (n % j) == 0:
return False
return True
if __name__ == '__main__':
import doctest
doctest.testmod()