Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("\n———————————————————————————————————————————————\n")
- print(" Таблицы A, B, C .. versa 1.0 ")
- print(" by soviet~ ")
- print(" ")
- print(" good luck))0")
- print(" ")
- print("\n———————————————————————————————————————————————\n")
- en_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- function math.createInfTable(num, expr)
- local loadString = "";
- for i=1,num do
- loadString = loadString .. " " .. string.sub(en_alphabet, i, i);
- end
- -- print(loadString .. " " .. expr .. "\n")
- print(loadString .. " R\n")
- local loadString = "";
- for i=1,num do
- local letter = string.sub(en_alphabet, i, i);
- loadString = loadString .. "for " .. letter .. "=0,1 do ";
- end
- loadString = loadString .. "if(" .. expr .. ") then print(''";
- for y=1,num do
- loadString = loadString .. " .. ' ' .. " .. string.sub(en_alphabet, y, y);
- end
- loadString = loadString .. " .. ' ' .. '1') else";
- loadString = loadString .. " print(''";
- for y=1,num do
- loadString = loadString .. " .. ' ' .. " .. string.sub(en_alphabet, y, y);
- end
- loadString = loadString .. " .. ' ' .. '0') end";
- for i=1,num do
- loadString = loadString .. " end"
- end
- assert(load(loadString)) ();
- end
- repeat
- print(" Кол-во букв:\n")
- lettersNum = io.read();
- if(tonumber(lettersNum) > 6) then lettersNum = 6 end;
- print("\n Выражение:\n")
- lettersExpr = io.read();
- print("\n_________________________________________________\n")
- print("\n Таблица построена:\n\n")
- math.createInfTable(lettersNum, lettersExpr)
- print("\n_________________________________________________\n")
- until 0 == 1
- function math.eval(eval)
- return assert(load("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, must)
- if(math.isInt(num)) then return "Целое: " .. num; end
- local oldNum = num;
- local smesh = false;
- local znam = 10^math.detectNumbers(num);
- local chisl = num * znam;
- local celoe = 0;
- 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
- for x = 0,1000 do
- for y = 0,1000 do
- if(math.equalOffset(x/y, oldNum)) then
- chisl = x
- znam = y
- 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
- return celoe;
- 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
- -- return " " .. spaces .. chisl .. "\n Дробь: " .. celoe .. " ——" .. tires .. " => " .. celoe .. " + ( " .. chisl .. " / " .. znam.. " )\n " .. spaces .. znam .. "\n\n Десятичная: " .. num
- return " " .. spaces .. chisl .. "\n Дробь: " .. celoe .. " ——" .. tires .. "\n " .. spaces .. znam .. "\n\n Десятичная: " .. num
- else
- -- return " " .. chisl .. "\n Дробь: ——" .. tires .. " => ( " .. chisl .. " / " .. znam.. " )\n " .. znam .. "\n\n Десятичная: " .. num
- return " " .. chisl .. "\n Дробь: ——" .. tires .. "\n " .. znam .. "\n\n Десятичная: " .. num
- end
- end
- else
- if(must) then
- return num;
- else
- return " Десятичная: " .. num .. " ( десятичной )";
- end
- end
- end
- repeat
- print(" Теперь вводим дробь:\n")
- repeat
- float = math.eval(io.read());
- until float and math.floor(float)
- print("\n " .. math.findCommon(float) .. "\n")
- print("———————————————————————————————————————————————\n")
- float = nil;
- until 0 == 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement