From 18711e0b43002a0a0091bfb8d183fd87ac559ae2 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Mon, 28 Jan 2019 13:00:07 -0500 Subject: [PATCH] Fixed problem with getFactos that always adds goalNumber to factors --- Algorithms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Algorithms.py b/Algorithms.py index 1163b0a..1df15c6 100644 --- a/Algorithms.py +++ b/Algorithms.py @@ -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))