Skip to content

Instantly share code, notes, and snippets.

@ThaisRobba
Created February 11, 2014 06:45
Show Gist options
  • Save ThaisRobba/8930302 to your computer and use it in GitHub Desktop.
Save ThaisRobba/8930302 to your computer and use it in GitHub Desktop.
Polynomial function for Lua (outputs value based on a numbers table and an x value)
local sum = 0
function polynomial(t, x)
--t is a table, x is the x value
for i=1, #t do
sum = sum+t[#t -i+1]*x^(i-1) --Travels in reverse through the table
end
return print(sum) --prints the result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment