Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getSymbol(numbers, result)
- local function explode(e, sep)
- local result = {} e:gsub("[^".. sep .."]+", function(s) table.insert(result, s:match("^%s*(.-)%s*$")) end)
- return result
- end
- local s = {"+", "-", "*", "/", "^"}
- local exp = explode(numbers, " ")
- local ret = nil
- for sig = 1, #s do
- local v = loadstring("return " .. exp[1] .. s[sig] .. exp[2])()
- if v == result then
- ret = exp[1] .." " .. s[sig] .." " .. exp[2] .. " = ".. v
- end
- end
- return ret
- end
Advertisement
Add Comment
Please, Sign In to add comment