Friday, 15 May 2015

math - [Lua]: Dividing numbers through two tables -



math - [Lua]: Dividing numbers through two tables -

what have 2 tables; 1 contains unspecified amount of numbers, sec table. i'm trying have first table split every number value in every number value in sec table. i've tried next it's can think have worked, not tells me trying perform arithmetic on nil value;

function findfactors( num ) local factors = { } local x = 0 while ( x < num ) x = x + 1 if ( num % x == 0 ) table.insert( factors, "±" .. x ) end end homecoming factors end function findzeros( a, b, c ) local zeros = { } local constant = findfactors( c ) if ( >= 2 ) local coefficient = findfactors(a) _, firstchild in pairs( constant ) _, secondchild in pairs( coefficient ) local num1, num2 = tonumber( firstchild ), tonumber( secondchild ) if num1 , num2 table.insert( zeros, (num1 / num2) ) end end end print( table.concat (zeros, ",") ) elseif < 2 print( table.concat (constant, ",") ) end end findzeros( 3, 4, 6 )

i can't seem find way i'm trying i'm new lua. help on how split number values between 2 tables appreciated.

table.insert( factors, "±" .. x )

here, inserting factors string "±1", "±2", etc. that's not valid number representation. if want insert both positive , negative numbers, seek this:

table.insert(factors, x) table.insert(factors, -x)

note here x , -x numbers, not strings, can omit phone call of tonumber in findzeros.

math lua

No comments:

Post a Comment