|
| 08 Aug 2012 06:31 AM |
challenge (expert scripters): create a function that will work on this:
_G.graph.Start = -10 _G.graph.End = 10 _G.graph.Step = 1 _G.graph.custom_vars = {} for x,y,i in _G.graph:f("x*-x") do print(i,x,y) end
Info: Start is where the graph starts End is where the graph ends Step is how it counts custom_vars is custom defineded variables in the formula f is the function that generates the points to the graph it have to return three values x, y and the index index always starts at 1 the function have to check for formula error before it generates the graph points and return error if found
Now it is up to you to find the correct working function to it, the it there and I will check if it is correct
Good luck! |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 06:39 AM |
The challenge is to make the graph count by ones and subtract ten from the end result?
I don't think you've explained this correctly... |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 06:46 AM |
You have to make this function to transform for example the string "x*-x" into a graph function _G.graph:f("x*-x")
on this "x*-x" when x is equal 2 then, y is equal -4 |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 08 Aug 2012 06:49 AM |
| i dont think you know the meaning of calling functions with : |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 06:52 AM |
| I know what it meaning I have created function before I created this challenge my function works. |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 07:23 AM |
I got this and it works
function _G.graph.f(v) _G.graph.runs = 0 return assert(loadstring([[ if _G.graph.runs < _G.graph.End - _G.graph.Start then _G.graph.runs = _G.graph.runs + 1 x = _G.graph.Start + (_G.graph.Step * _G.graph.runs)
y = ]] .. v .. [[ return x,y,_G.graph.runs end]])) end
But wtf is custom_vars even supposed to mean |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 07:40 AM |
the script is very correct exept of one thing and it is G.graph.Step, when I adds the number 2, doubles the end result and that is not correct and you are missing _G.graph.custom_vars.
_G.graph.custom_vars is to add custom-defined variables into the function
example on use is: _G.graph.custom_vars = {v=3,w="x+x^2"}
for x,y,i in _G.graph:f("v/w*x") print(i,x,y) end |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 07:56 AM |
function _G.graph.f(v) _G.graph.runs = 0
_G.cvar = {}
for var,val in pairs(_G.graph.custom_vars) do assert(loadstring("_G.cvar." .. var .. " = " .. val))() end
return assert(loadstring([[ if _G.graph.Start + (_G.graph.Step * (_G.graph.runs-1)) < _G.graph.End then _G.graph.runs = _G.graph.runs + 1
x = _G.graph.Start + (_G.graph.Step * (_G.graph.runs-1))
y = ]] .. v .. [[
return x,y,_G.graph.runs end]])) end
Am I doing it right? |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 08:06 AM |
got an error when using _G.graph.custom_vars, message: [string "_G.cvar.w = x*x^2"]:1: attempt to perform arithmetic on global 'x' (a nil value) and another: [string "if _G.graph.Start + (_G.graph.Step * (_G.gr..."]:6: attempt to perform arithmetic on global 'v' (a nil value)
custom_vars is still useless. |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 08:11 AM |
| When you just tested it, you were making w rely on x, but in the example you gave me you had x relying on w. I have to assign either x or w first, and the first one can't rely on the second one. So which one is relying on which? |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 08:15 AM |
| you have to define x before the other variables so they can use it |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 08:26 AM |
I've lost interest in the challenge as I seem to be the only competitor and I don't see any compensation for the lost time.
I leave you to your endeavor, gentlemen. Or gentleman, as it is. |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 08:56 AM |
| It feels as if he's changing the rules, and personally I don't understand what he wants us to do... |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2012 09:11 AM |
I am not changing the rules I am trying to say it in other ways to do it easier to understand, but it looks like I failed.
And this is about to create a working script that will wroks with the script I added at the start, by reading the info. |
|
|
| Report Abuse |
|
|
| |
|