mirror of
https://bitbucket.org/Mattrixwv/luaclasses.git
synced 2025-12-06 18:33:59 -05:00
Fixed bug in getDivisors
This commit is contained in:
@@ -146,15 +146,11 @@ function getDivisors(goalNumber)
|
|||||||
--If the number is 1 return just itself
|
--If the number is 1 return just itself
|
||||||
elseif(goalNumber == 1) then
|
elseif(goalNumber == 1) then
|
||||||
divisors[#divisors+1] = 1;
|
divisors[#divisors+1] = 1;
|
||||||
--Otherwise add 1 and itself to the list
|
|
||||||
else
|
|
||||||
divisors[#divisors+1] = 1;
|
|
||||||
divisors[#divisors+1] = goalNumber;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--Start at 3 and loop through all numbers < (goalNumber / 2) looking for a number that divides it evenly
|
--Start at 3 and loop through all numbers < (goalNumber / 2) looking for a number that divides it evenly
|
||||||
local topPossibleDivisor = math.ceil(math.sqrt(goalNumber));
|
local topPossibleDivisor = math.ceil(math.sqrt(goalNumber));
|
||||||
local possibleDivisor = 2;
|
local possibleDivisor = 1;
|
||||||
while(possibleDivisor <= topPossibleDivisor) do
|
while(possibleDivisor <= topPossibleDivisor) do
|
||||||
--If you find one add it and the number it creates to the list
|
--If you find one add it and the number it creates to the list
|
||||||
if((goalNumber % possibleDivisor) == 0) then
|
if((goalNumber % possibleDivisor) == 0) then
|
||||||
|
|||||||
Reference in New Issue
Block a user