Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. print("\n———————————————————————————————————————————————\n")
  2. print(" Таблицы A, B, C .. versa 1.0 ")
  3. print(" by soviet~ ")
  4. print(" ")
  5. print(" good luck))0")
  6. print(" ")
  7. print("\n———————————————————————————————————————————————\n")
  8.  
  9. en_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  10.  
  11. function math.createInfTable(num, expr)
  12. local loadString = "";
  13. for i=1,num do
  14. loadString = loadString .. " " .. string.sub(en_alphabet, i, i);
  15. end
  16. -- print(loadString .. " " .. expr .. "\n")
  17. print(loadString .. " R\n")
  18. local loadString = "";
  19. for i=1,num do
  20. local letter = string.sub(en_alphabet, i, i);
  21. loadString = loadString .. "for " .. letter .. "=0,1 do ";
  22. end
  23.  
  24. loadString = loadString .. "if(" .. expr .. ") then print(''";
  25. for y=1,num do
  26. loadString = loadString .. " .. ' ' .. " .. string.sub(en_alphabet, y, y);
  27. end
  28. loadString = loadString .. " .. ' ' .. '1') else";
  29.  
  30. loadString = loadString .. " print(''";
  31. for y=1,num do
  32. loadString = loadString .. " .. ' ' .. " .. string.sub(en_alphabet, y, y);
  33. end
  34. loadString = loadString .. " .. ' ' .. '0') end";
  35.  
  36. for i=1,num do
  37. loadString = loadString .. " end"
  38. end
  39.  
  40. assert(load(loadString)) ();
  41. end
  42.  
  43. repeat
  44.  
  45. print(" Кол-во букв:\n")
  46.  
  47. lettersNum = io.read();
  48.  
  49. if(tonumber(lettersNum) > 6) then lettersNum = 6 end;
  50.  
  51. print("\n Выражение:\n")
  52.  
  53. lettersExpr = io.read();
  54.  
  55. print("\n_________________________________________________\n")
  56.  
  57. print("\n Таблица построена:\n\n")
  58.  
  59. math.createInfTable(lettersNum, lettersExpr)
  60.  
  61. print("\n_________________________________________________\n")
  62.  
  63. until 0 == 1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. function math.eval(eval)
  117. return assert(load("return " .. eval)) ();
  118. end
  119.  
  120. function math.isFloat(int)
  121. return int ~= math.floor(int)
  122. end
  123.  
  124. function math.isInt(int)
  125. return int == math.floor(int)
  126. end
  127.  
  128. function math.detectNumbers(flt)
  129. flt = tostring(flt)
  130. if(string.find(flt, "%.")) then
  131. return string.len(string.gsub(flt, "[%d]+%.", ""))
  132. else
  133. return 0
  134. end
  135. end
  136.  
  137. function math.removeAfter(flt)
  138. flt = tostring(flt)
  139. return string.gsub(flt, "%.[%d]+", "");
  140. end
  141.  
  142. function math.nod(a,b,...)
  143. if b == nil then return a end
  144. while a ~= 0 and b ~= 0 do
  145. if a > b then
  146. a = a % b
  147. else
  148. b = b % a
  149. end
  150. end
  151. return math.nod(a + b,...)
  152. end
  153.  
  154. function math.onlyDigits(num, numDecimalPlaces)
  155. local mult = 10^(numDecimalPlaces or 0)
  156. return math.floor(num * mult + 0.5) / mult
  157. end
  158.  
  159. function math.equalOffset(x, y)
  160.  
  161. return x > y - 0.0000003 and x < y + 0.0000003
  162.  
  163. end
  164.  
  165. function math.findCommon(num, must)
  166.  
  167. if(math.isInt(num)) then return "Целое: " .. num; end
  168.  
  169. local oldNum = num;
  170.  
  171. local smesh = false;
  172.  
  173. local znam = 10^math.detectNumbers(num);
  174.  
  175. local chisl = num * znam;
  176.  
  177. local celoe = 0;
  178.  
  179. if(chisl > znam) then
  180.  
  181. celoe = math.floor(chisl/znam)
  182.  
  183. chisl = math.fmod(chisl,znam)
  184.  
  185. oldNum = oldNum - math.floor(oldNum)
  186.  
  187. if(chisl == znam or chisl == 0) then
  188.  
  189. smesh = true;
  190.  
  191. end
  192.  
  193. end
  194.  
  195. for x = 0,1000 do
  196.  
  197. for y = 0,1000 do
  198.  
  199. if(math.equalOffset(x/y, oldNum)) then
  200.  
  201. chisl = x
  202.  
  203. znam = y
  204.  
  205. break;
  206.  
  207. end
  208.  
  209. end
  210.  
  211. end
  212.  
  213. local nod = math.nod(chisl, znam)
  214.  
  215. if(nod and nod > 1) then
  216.  
  217. znam = znam / nod;
  218.  
  219. chisl = chisl / nod;
  220.  
  221. end
  222.  
  223. if((math.isInt(chisl) and math.isInt(znam)) or smesh or true) then
  224.  
  225. if(smesh) then
  226.  
  227. return celoe;
  228.  
  229. else
  230.  
  231. local tires = "";
  232.  
  233. for i=1,string.len(znam) do
  234.  
  235. tires = tires .. "—";
  236.  
  237. end
  238.  
  239. if(celoe > 0) then
  240.  
  241. local spaces = "";
  242.  
  243. for i=1,string.len(celoe) do
  244.  
  245. spaces = spaces .. " ";
  246.  
  247. end
  248.  
  249. -- return " " .. spaces .. chisl .. "\n Дробь: " .. celoe .. " ——" .. tires .. " => " .. celoe .. " + ( " .. chisl .. " / " .. znam.. " )\n " .. spaces .. znam .. "\n\n Десятичная: " .. num
  250.  
  251. return " " .. spaces .. chisl .. "\n Дробь: " .. celoe .. " ——" .. tires .. "\n " .. spaces .. znam .. "\n\n Десятичная: " .. num
  252.  
  253. else
  254.  
  255. -- return " " .. chisl .. "\n Дробь: ——" .. tires .. " => ( " .. chisl .. " / " .. znam.. " )\n " .. znam .. "\n\n Десятичная: " .. num
  256.  
  257. return " " .. chisl .. "\n Дробь: ——" .. tires .. "\n " .. znam .. "\n\n Десятичная: " .. num
  258.  
  259. end
  260.  
  261. end
  262.  
  263. else
  264.  
  265. if(must) then
  266.  
  267. return num;
  268.  
  269. else
  270.  
  271. return " Десятичная: " .. num .. " ( десятичной )";
  272.  
  273. end
  274.  
  275. end
  276.  
  277. end
  278.  
  279. repeat
  280.  
  281. print(" Теперь вводим дробь:\n")
  282.  
  283. repeat
  284.  
  285. float = math.eval(io.read());
  286.  
  287. until float and math.floor(float)
  288.  
  289. print("\n " .. math.findCommon(float) .. "\n")
  290.  
  291. print("———————————————————————————————————————————————\n")
  292.  
  293. float = nil;
  294.  
  295. until 0 == 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement