def prime_factors(n):
factor = 2
while n > 1:
if n % factor == 0:
yield factor
n = n / factor
else:
factor += 1
This ended up being simpler and more beautiful than I was expecting. I think I'm falling in love with python all over again. *snif*
def prime_factors(n):
factor = 2
while n > 1:
if n % factor == 0:
yield factor
n = n / factor
else:
factor += 1
No comments:
Post a Comment