Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("\n———————————————————————————————————————————————\n")
- print(" Квадратные уравнения versa 1.1 ")
- print(" by soviet~ ")
- print(" ")
- print(" БУДЬТЕ ОСТОРОЖНЫ И НЕ ПАЛИТЕСЬ")
- print(" good luck))0")
- print(" ")
- print("\n———————————————————————————————————————————————\n")
- function math.eval(eval)
- return assert(loadstring('return "" .. ' .. eval)) ();
- end
- function math.isFloat(int)
- return int ~= math.floor(int)
- end
- function math.isInt(int)
- return int == math.floor(int)
- end
- function math.detectNumbers(flt)
- flt = tostring(flt)
- if(string.find(flt, "%.")) then
- return string.len(string.gsub(flt, "[%d]+%.", ""))
- else
- return 0
- end
- end
- function math.removeAfter(flt)
- flt = tostring(flt)
- return string.gsub(flt, "%.[%d]+", "");
- end
- function math.nod(a,b,...)
- if b == nil then return a end
- while a ~= 0 and b ~= 0 do
- if a > b then
- a = a % b
- else
- b = b % a
- end
- end
- return math.nod(a + b,...)
- end
- function math.onlyDigits(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function math.equalOffset(x, y)
- return x > y - 0.0000003 and x < y + 0.0000003
- end
- function math.findCommon(num, onlyNum, addition)
- if(math.isInt(num)) then
- if(onlyNum) then
- return num;
- else
- return "\n" .. addition .. num;
- end
- end
- local oldNum = num;
- local smesh = false;
- local znam = 10^math.detectNumbers(num);
- local chisl = num * znam;
- local celoe = 0;
- local isNegative = "+";
- if(tonumber(num) < 0) then isNegative = "-"; chisl = math.abs(chisl); znam = math.abs(znam); oldNum = math.abs(oldNum) end
- if(chisl > znam) then
- celoe = math.floor(chisl/znam)
- chisl = math.fmod(chisl,znam)
- oldNum = oldNum - math.floor(oldNum)
- if(chisl == znam or chisl == 0) then
- smesh = true;
- end
- end
- local foundNeed = false;
- for x = 2,100 do
- for y = 1,100 do
- if(math.equalOffset(y*math.sqrt(x), oldNum)) then
- if(not onlyNum) then
- print(addition .. y .. "√" .. x)
- end
- break;
- end
- if(foundNeed) then break; end
- end
- end
- for x = 0,10000 do
- for y = 0,10000 do
- if(math.equalOffset(x/y, oldNum)) then
- chisl = x
- znam = y
- foundNeed = true;
- break;
- end
- if(foundNeed) then break; end
- end
- end
- local nod = math.nod(chisl, znam)
- if(nod and nod > 1) then
- znam = znam / nod;
- chisl = chisl / nod;
- end
- if((math.isInt(chisl) and math.isInt(znam)) or smesh or true) then
- if(smesh) then
- if(onlyNum) then
- return isNegative .. " " .. celoe;
- else
- return addition .. isNegative .. " " .. celoe;
- end
- else
- local tires = "";
- for i=1,string.len(znam) do
- tires = tires .. "—";
- end
- if(celoe > 0) then
- local spaces = "";
- for i=1,string.len(celoe) do
- spaces = spaces .. " ";
- end
- if(onlyNum) then
- return isNegative .. math.removeAfter(celoe) .. " " .. isNegative .. " ( " .. math.removeAfter(chisl) .. " / " .. math.removeAfter(znam) .. " )"
- else
- return "\n " .. spaces .. math.removeAfter(chisl) .. "\n" .. addition .. isNegative .. " " .. math.removeAfter(celoe) .. " ——" .. tires .. "\n " .. spaces .. math.removeAfter(znam) .. "\n\n" .. "\n" .. addition .. num
- end
- else
- if(onlyNum) then
- return isNegative .. " ( " .. math.removeAfter(chisl) .. " / " .. math.removeAfter(znam) .. " )"
- else
- return "\n " .. math.removeAfter(chisl) .. "\n" .. addition .. isNegative .. " ——" .. tires .. "\n " .. math.removeAfter(znam) .. "\n\n" .. "\n" .. addition .. num;
- end
- end
- end
- else
- if(onlyNum) then
- return num;
- else
- return "\n" .. addition .. num;
- end
- end
- end
- function round(num, numDecimalPlaces)
- if numDecimalPlaces and numDecimalPlaces>0 then
- local mult = 10^numDecimalPlaces
- return math.floor(num * mult + 0.5) / mult
- end
- return math.floor(num + 0.5)
- end
- repeat
- print(" Теперь вводим a:\n")
- a = io.read()
- print(" Теперь вводим b:\n")
- b = io.read()
- print(" Теперь вводим c:\n")
- c = io.read()
- D = (b*b) - (4*a*c)
- print("\n———————————————————————————————————————————————\n")
- print(" Способ 1.")
- print("\n———————————————————————————————————————————————\n")
- print("\n ФОРМУЛЫ\n")
- print("\n D = b² - 4ac\n")
- sqrtOld = math.sqrt(math.abs(D))
- if(math.isFloat(sqrtOld)) then sqrt = math.findCommon(sqrtOld, true) end;
- if(D > 0) then
- print("\n -b - √D")
- print(" x1 = —————————")
- print(" 2a\n")
- print(" -b + √D")
- print(" x2 = —————————")
- print(" 2a")
- x1 = ((b*-1)-sqrtOld)/(2*a)
- x2 = ((b*-1)+sqrtOld)/(2*a)
- print("\n\n РЕШЕНИЕ\n\n")
- print(" D = " .. b .. "² - 4*" .. a .. "*" .. c)
- print(" D = " .. b*b .. " - " .. 4*a*c)
- print("\n D = " .. D)
- print("\n " .. b*-1 .. " - √" .. D)
- print(" x1 = ————————————————————")
- if(a == 1) then
- print(" " .. a)
- else
- print(" 2 * " .. a)
- end
- print("\n " .. b*-1 .. " - " .. sqrtOld)
- print(" x1 = ————————————————————")
- print(" " .. 2*a)
- print(math.findCommon(x1, false, " x1 = "))
- print("\n\n " .. b*-1 .. " + √" .. D)
- print(" x2 = ————————————————————")
- if(a == 1) then
- print(" " .. a)
- else
- print(" 2 * " .. a)
- end
- print("\n " .. b*-1 .. " + " .. sqrtOld)
- print(" x2 = ————————————————————")
- print(" " .. 2*a)
- print(math.findCommon(x2, false, " x2 = "))
- print("\n\n ОТВЕТ: " .. math.findCommon(x1, true) .. "; " .. math.findCommon(x2, true))
- print("\n———————————————————————————————————————————————\n")
- print(" Способ 2.")
- print("\n———————————————————————————————————————————————\n")
- print("\n ФОРМУЛЫ\n")
- x1 = (b/2)*-1+math.sqrt(math.abs((b/2)^2-c))
- x2 = (b/2)*-1-math.sqrt(math.abs((b/2)^2-c))
- print("\n p")
- print(" x1 = - ——— + √(p/2)²-q")
- print(" 2\n")
- print("\n p")
- print(" x2 = - ——— - √(p/2)²-q")
- print(" 2\n")
- print("\n\n РЕШЕНИЕ\n\n")
- print("\n " .. b)
- print(" x1 = - ——— - √(" .. b .. "/2)²-" .. c)
- print(" 2")
- print("\n x1 = " .. b/2*-1 .. " - √(" .. b/2 .. ")²-" .. c)
- print(math.findCommon(x1, false, " x1 = "))
- print("\n " .. b)
- print(" x2 = - ——— + √(" .. b .. "/2)²-" .. c)
- print(" 2")
- print("\n x2 = " .. b/2*-1 .. " + √(" .. b/2 .. ")²-" .. c)
- print(math.findCommon(x2, false, " x2 = "))
- print("\n\n ОТВЕТ: " .. math.findCommon(x1, true) .. "; " .. math.findCommon(x2, true))
- if(math.fmod(b, 2) == 0) then
- print("\n———————————————————————————————————————————————\n")
- print(" Способ 3.")
- print("\n———————————————————————————————————————————————\n")
- print("\n ФОРМУЛЫ\n")
- k = b/2
- x1 = ((k*-1)+math.sqrt(k^2-a*c))/a;
- x2 = ((k*-1)-math.sqrt(k^2-a*c))/a;
- print("\n -k+√(k²-ac)")
- print(" x1 = ————————")
- print(" a\n")
- print("\n -k-√(k²-ac)")
- print(" x2 = ————————")
- print(" a\n")
- print("\n\n РЕШЕНИЕ\n\n")
- print("\n " .. k*-1 .. " + √(" .. k .. "²-" .. a .. "*" .. c .. ")")
- print(" x1 = ———————————")
- print(" " .. a .. "\n")
- print("\n x1 = ( " .. k*-1 .. " + √ ( " .. k^2 .. " - " .. a*c .. " ) ) / " .. a)
- print(math.findCommon(x1, false, " x1 = "))
- print("\n " .. k*-1 .. " - √(" .. k .. "²-" .. a .. "*" .. c .. ")")
- print(" x2 = ———————————")
- print(" " .. a .. "\n")
- print("\n x2 = ( " .. k*-1 .. " - √ ( " .. k^2 .. " - " .. a*c .. " ) ) / " .. a)
- print(math.findCommon(x2, false, " x2 = "))
- print("\n\n ОТВЕТ: " .. math.findCommon(x1, true) .. "; " .. math.findCommon(x2, true))
- end
- elseif(D < 0) then
- print("\n\n РЕШЕНИЕ\n\n")
- print(" D = " .. b .. "² - 4*" .. a .. "*" .. c)
- print(" D = " .. b*b .. " - " .. 4*a*c)
- print("\n D = " .. D)
- print("\n\n корней нет.")
- print("\n\n ОТВЕТ: корней нет.")
- elseif(D == 0) then
- print("\n -b")
- print(" x = ———————")
- print(" 2a\n")
- print("\n\n РЕШЕНИЕ\n\n")
- print(" D = " .. b .. "² - 4*" .. a .. "*" .. c)
- print(" D = " .. b*b .. " - " .. 4*a*c)
- print("\n D = " .. D)
- print("\n " .. b*-1)
- print(" x = ————————————")
- if(a == 1) then
- print(" " .. a)
- else
- print(" 2 * " .. a)
- end
- x = round((b*-1)/(2*a), 3)
- print("\n x = " .. math.findCommon(x, true))
- print("\n\n ОТВЕТ: " .. math.findCommon(x, true))
- --print(" " .. b*-1 .. "\nx = —————————————————— = " .. x .. " \n " .. 2*a .. "\n")
- end
- print("\n———————————————————————————————————————————————\n\n\n")
- until 0 == 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement