Fixed bug in getFib functions that gave incorrect

answers for low subscripts
This commit is contained in:
2019-03-26 02:02:06 -04:00
parent 382e441a29
commit a8d62c462c

View File

@@ -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)