Skymagnum

Untitled

Jun 4th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.51 KB | None | 0 0
  1. function getSymbol(numbers, result)
  2.  
  3. local function explode(e, sep)
  4.     local result = {}    e:gsub("[^".. sep .."]+", function(s) table.insert(result, s:match("^%s*(.-)%s*$")) end)
  5.     return result
  6. end
  7.  
  8.  local s = {"+", "-", "*", "/", "^"}
  9.  local exp = explode(numbers, " ")
  10.  local ret = nil
  11.  
  12. for sig = 1, #s do
  13.     local v = loadstring("return " .. exp[1] .. s[sig] .. exp[2])()
  14.  
  15.     if v == result then
  16.         ret = exp[1] .." " .. s[sig] .." " .. exp[2] .. " = ".. v
  17.     end
  18. end
  19.  
  20.     return ret
  21. end
Advertisement
Add Comment
Please, Sign In to add comment