Created
May 5, 2014 11:52
-
-
Save bcicen/970bd8393976e3329c1c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python2 | |
import sys | |
a = sys.argv[1] | |
print "finding prime factors of %d" % int(a) | |
def findfirstfactor(number): | |
b = 1 | |
test = 1 | |
factorlist = [] | |
while test != 0: | |
b +=1 | |
if b >= int(number): | |
return None | |
test = int(number) % int(b) | |
firstfactor = b | |
secondfactor = int(number) / b | |
factorlist.extend([firstfactor, secondfactor]) | |
return factorlist | |
def testmorefactors(factors): | |
morefactors = [] | |
if len(factors) == 1: | |
return None | |
for factor in factors: | |
test = findfirstfactor(factor) | |
if test is not None: | |
morefactors.append(factor) | |
if morefactors is None: | |
return None | |
else: | |
return morefactors | |
factors = findfirstfactor(a) | |
print factors | |
if factors is not None: | |
morefactors = testmorefactors(factors) | |
while morefactors: | |
for factor in morefactors: | |
factors.remove(factor) | |
for newfactors in findfirstfactor(factor): | |
factors.append(newfactors) | |
morefactors = testmorefactors(factors) | |
print (factors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment