mirror of
https://bitbucket.org/Mattrixwv/luaclasses.git
synced 2025-12-06 18:33:59 -05:00
Fixed bug in getFib functions that gave incorrect
answers for low subscripts
This commit is contained in:
@@ -183,14 +183,18 @@ function getFib(goalSubscript)
|
||||
end
|
||||
|
||||
--Loop through the list, generating Fibonacci numbers until it finds the correct subscript
|
||||
local fibLoc = 3;
|
||||
local fibLoc = 2;
|
||||
while(fibLoc <= goalSubscript) do
|
||||
fibNums[fibLoc % 3] = fibNums[(fibLoc - 1) % 3] + fibNums[(fibLoc - 2) % 3];
|
||||
fibNums[(fibLoc % 3) + 1] = fibNums[((fibLoc - 1) % 3) + 1] + fibNums[((fibLoc - 2) % 3) + 1];
|
||||
fibLoc = fibLoc + 1;
|
||||
end
|
||||
|
||||
--Return the propper number
|
||||
return fibNums[(fibLoc - 1) % 3];
|
||||
local answerLocation = ((fibLoc - 1) % 3);
|
||||
if(answerLocation == 0) then
|
||||
answerLocation = 3;
|
||||
end
|
||||
return fibNums[answerLocation];
|
||||
end
|
||||
|
||||
function getLargeFib(goalSubscript)
|
||||
@@ -204,14 +208,18 @@ function getLargeFib(goalSubscript)
|
||||
end
|
||||
|
||||
--Loop through the list, generating Fibonacci numbers until it finds the correct subscript
|
||||
local fibLoc = 3;
|
||||
local fibLoc = 2;
|
||||
while(fibLoc <= goalSubscript) do
|
||||
fibNums[fibLoc % 3] = bigint.add(fibNums[(fibLoc - 1) % 3], fibNums[(fibLoc - 2) % 3]);
|
||||
fibNums[(fibLoc % 3) + 1] = bigint.add(fibNums[((fibLoc - 1) % 3) + 1], fibNums[((fibLoc - 2) % 3) + 1]);
|
||||
fibLoc = fibLoc + 1;
|
||||
end
|
||||
|
||||
--Return the propper number
|
||||
return fibNums[(fibLoc - 1) % 3];
|
||||
local answerLocation = ((fibLoc - 1) % 3);
|
||||
if(answerLocation == 0) then
|
||||
answerLocation = 3;
|
||||
end
|
||||
return fibNums[answerLocation];
|
||||
end
|
||||
|
||||
function getSum(ary)
|
||||
|
||||
Reference in New Issue
Block a user