mirror of
https://bitbucket.org/Mattrixwv/luaclasses.git
synced 2026-02-03 19:52:33 -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
|
end
|
||||||
|
|
||||||
--Loop through the list, generating Fibonacci numbers until it finds the correct subscript
|
--Loop through the list, generating Fibonacci numbers until it finds the correct subscript
|
||||||
local fibLoc = 3;
|
local fibLoc = 2;
|
||||||
while(fibLoc <= goalSubscript) do
|
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;
|
fibLoc = fibLoc + 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
--Return the propper number
|
--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
|
end
|
||||||
|
|
||||||
function getLargeFib(goalSubscript)
|
function getLargeFib(goalSubscript)
|
||||||
@@ -204,14 +208,18 @@ function getLargeFib(goalSubscript)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Loop through the list, generating Fibonacci numbers until it finds the correct subscript
|
--Loop through the list, generating Fibonacci numbers until it finds the correct subscript
|
||||||
local fibLoc = 3;
|
local fibLoc = 2;
|
||||||
while(fibLoc <= goalSubscript) do
|
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;
|
fibLoc = fibLoc + 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
--Return the propper number
|
--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
|
end
|
||||||
|
|
||||||
function getSum(ary)
|
function getSum(ary)
|
||||||
|
|||||||
Reference in New Issue
Block a user