Fixed problem with getFactos that always adds goalNumber to factors

This commit is contained in:
2019-01-28 13:00:07 -05:00
parent 4557ad07db
commit 18711e0b43

View File

@@ -41,8 +41,6 @@ def getFactors(goalNumber: int):
primes = getPrimes(math.ceil(math.sqrt(goalNumber))) #If there is a prime it must be <= sqrt(num)
factors = []
#If you didn't get any primes the number itself must be a prime
factors.append(goalNumber)
#You need to step through each prime and see if it is a factor in the number
cnt = 0
while((cnt < len(primes)) and (goalNumber > 1)):
@@ -55,6 +53,10 @@ def getFactors(goalNumber: int):
else:
cnt += 1
#If you didn't get any factors the number itself must be a prime
if(len(factors) == 0):
factors.append(goalNumber)
#If for some reason the goalNumber is not 0 print an error message
if(goalNumber > 1):
print("There was an error in getFactors(). A leftover of " + str(goalNumber))