Log in to vote

4
I'm study Linear Relationships in mathamatics, I came across the formatting of the table used to provide the positioning of each value of the Graph, Looking something like this...

Table[i] | Table[v]

1 3.50 2. 7.00 3. 10.50 4. 14.00 5. 17.50

For those who don't understand how liner equations work, they're simply a calculated line drawn on a positive to negative XY Graph, it takes the variable, usually a number. Multiplies it by how many times called, Eg, Table[i] (How many variables exist by interval; `0-#?`

) is 5. Table[v] is `3.50`

, the rest is self explanatory with the formatting of the table above.

I decided to take a chance on creating a complicated-ish algorithm on how to present the Graph through Console, here's what I've done. This is the formula `table_[i]*variable`

I am getting nothing, but blank space, not even a hextag. I know the algorithm is quite messy and probably wrong as I wrote it literally a few minutes ago, and am too busy with midterms to figure out the issue(s), could anyone tell me?

local table_ = {'startkey'} local listlength, variable local chart = {} for i,_ in ipairs(table_) do listlength = 5; variable = 3.50 if (type(variable) ~= "number") then error("variable '"..variable.."' isn't an integer.") end table.remove(table_, 1) for i_ = listlength, listlength, 1 do if (#table_ ~= listlength) then table.insert(table_, tonumber(i_)) else break end; end; table.insert(chart, table_[i]*variable) end; for i = 1,#table_ do print(tostring(i)..[[ - ]]..table.concat(chart)) end;

*Please don't mind the way I use ;, I'm transferring from another language, it also doesn't entirely effect the Script at all so it doesn't matter*.

Thanks!

0

My first guess is line 13. You did `table.insert(chart)` but chart isn't defined as table as of yet. Zafirua 1348 — 2y

0

Checking for the type is simply by doing `if (type(value) == "number") then {...}` Zafirua 1348 — 2y

0

I though that would happen too, only nothing really changes if I do '= {}' Ziffixture 6785 — 2y

0

Another problem is that the loop is starting from 5 and ending at 5 at line 06. Simply change from 1, listlength, as opposed to listlength, listlength. Or is it like supposed to be like that? Zafirua 1348 — 2y

View all comments (14 more)

0

As well as another problem is that table_ is empty. Since it is empty, I doubt if the generic for loop is even looping at all. Zafirua 1348 — 2y

0

Could I out a variable in there called 'startkey' then have it run for that, loop everything in, then once everythings in, it'll check again with the new stuff in the same loop? Ziffixture 6785 — 2y

0

Sure. That is up to you to decide. My job is to assist you whichever path you take on. Zafirua 1348 — 2y

0

it's suppsoed to write 5,5,1 for an adding for loop Ziffixture 6785 — 2y

0

From my understanding, do you wish to print the multiples of 3.5? Zafirua 1348 — 2y

0

Yes, I know this kethod is pointless, yet it still works, I do this for the teacher every unit, make an algorithm that calculates the work for everyone in class. Also, is the updates code better? Ziffixture 6785 — 2y

0

Writing effective algorithms must be your priority since you want to finish executing the code in the most linear time complexity you can get. Zafirua 1348 — 2y

0

Yes, and method*;) also, does error() stop the script as if returning end? Ziffixture 6785 — 2y

0

error() stops the code and outputs the error message if given. Zafirua 1348 — 2y

0

Thanks, would does the code above seem okay? Ziffixture 6785 — 2y

0

Seems too complicated for simple code tbh. Zafirua 1348 — 2y

0

It may be, yet the method works perfectly fine, I'm just writing it this way to strech my knowledge and also make me look more nerdy;) Ziffixture 6785 — 2y

0

Well I posted my solution if you want to check it out Zafirua 1348 — 2y

0

Please accept the answer if it helped you so we both earn some reputation point! Zafirua 1348 — 2y

Log in to vote

1
local t = {}; local endNum = 5; local variable = 3.5; while (#t ~= endNum) do table.insert(t, #t * variable); end for i, v in ipairs(t) do print(i .. " - " .. v); end

0

Yeah, this is basically what I originally wrote, but I decided to stretch it out, I'll continue messing with it, thanks Ziffixture 6785 — 2y