Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Root
--lua 5.3 -- Port of https://rextester.com/discussion/TAGOI61149 to Lua. local function checkNumber(num) assert(math.type(num), tostring(num) .. " is not a number") assert(num == num and num ~= math.huge, tostring(num) .. " is not finite") end local function checkInteger(num) checkNumber(num) assert(math.type(num) == "integer", tostring(num) .. " is not an integer") end local function integralRoot(num, pow) pow = (pow ~= nil) and pow or 2 checkNumber(num) checkInteger(pow) for i = 1, num do if i ^ pow == num then return i elseif i ^ pow > num then return i - 1 end end end local function root(num, pow, prc) pow = (pow ~= nil) and pow or 2 prc = (prc ~= nil) and prc or 15 checkNumber(num) checkInteger(pow) checkInteger(prc) local int_root = integralRoot(num, pow) if int_root ^ pow == num then return int_root end local str = int_root .. "." for i = 1, prc do local added = false for j = 1, 9 do local n = tonumber(str .. j) if n ^ pow == num then return n elseif n ^ pow > num then str = str .. (j - 1) added = true break end end if not added then str = str .. "9" end end return tonumber(str) end local x = 125096235 print(root(x), math.sqrt(x))
run
|
edit
|
history
|
help
0
bf-asm compiler test 2
RSA KEY GENERATOR (LUA)
kraft1c
Creating habits v3, Lua
hack
Testingassets
True every 5
Find primes until e
roulette
help with lua number input