Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.40 KB | None | 0 0
  1. print("\n———————————————————————————————————————————————\n")
  2. print(" Квадратные уравнения versa 1.1 ")
  3. print(" by soviet~ ")
  4. print(" ")
  5. print(" БУДЬТЕ ОСТОРОЖНЫ И НЕ ПАЛИТЕСЬ")
  6. print(" good luck))0")
  7. print(" ")
  8. print("\n———————————————————————————————————————————————\n")
  9.  
  10. function math.eval(eval)
  11. return assert(loadstring('return "" .. ' .. eval)) ();
  12. end
  13.  
  14. function math.isFloat(int)
  15. return int ~= math.floor(int)
  16. end
  17.  
  18. function math.isInt(int)
  19. return int == math.floor(int)
  20. end
  21.  
  22. function math.detectNumbers(flt)
  23. flt = tostring(flt)
  24. if(string.find(flt, "%.")) then
  25. return string.len(string.gsub(flt, "[%d]+%.", ""))
  26. else
  27. return 0
  28. end
  29. end
  30.  
  31. function math.removeAfter(flt)
  32. flt = tostring(flt)
  33. return string.gsub(flt, "%.[%d]+", "");
  34. end
  35.  
  36. function math.nod(a,b,...)
  37. if b == nil then return a end
  38. while a ~= 0 and b ~= 0 do
  39. if a > b then
  40. a = a % b
  41. else
  42. b = b % a
  43. end
  44. end
  45. return math.nod(a + b,...)
  46. end
  47.  
  48. function math.onlyDigits(num, numDecimalPlaces)
  49. local mult = 10^(numDecimalPlaces or 0)
  50. return math.floor(num * mult + 0.5) / mult
  51. end
  52.  
  53. function math.equalOffset(x, y)
  54.  
  55. return x > y - 0.0000003 and x < y + 0.0000003
  56.  
  57. end
  58.  
  59. function math.findCommon(num, onlyNum, addition)
  60.  
  61. if(math.isInt(num)) then
  62.  
  63. if(onlyNum) then
  64.  
  65. return num;
  66.  
  67. else
  68.  
  69. return "\n" .. addition .. num;
  70.  
  71. end
  72.  
  73. end
  74.  
  75. local oldNum = num;
  76.  
  77. local smesh = false;
  78.  
  79. local znam = 10^math.detectNumbers(num);
  80.  
  81. local chisl = num * znam;
  82.  
  83. local celoe = 0;
  84.  
  85. local isNegative = "+";
  86.  
  87. if(tonumber(num) < 0) then isNegative = "-"; chisl = math.abs(chisl); znam = math.abs(znam); oldNum = math.abs(oldNum) end
  88.  
  89. if(chisl > znam) then
  90.  
  91. celoe = math.floor(chisl/znam)
  92.  
  93. chisl = math.fmod(chisl,znam)
  94.  
  95. oldNum = oldNum - math.floor(oldNum)
  96.  
  97. if(chisl == znam or chisl == 0) then
  98.  
  99. smesh = true;
  100.  
  101. end
  102.  
  103. end
  104.  
  105. local foundNeed = false;
  106.  
  107. for x = 2,100 do
  108.  
  109. for y = 1,100 do
  110.  
  111. if(math.equalOffset(y*math.sqrt(x), oldNum)) then
  112.  
  113. if(not onlyNum) then
  114.  
  115. print(addition .. y .. "√" .. x)
  116.  
  117. end
  118.  
  119. break;
  120.  
  121. end
  122.  
  123. if(foundNeed) then break; end
  124.  
  125. end
  126.  
  127. end
  128.  
  129. for x = 0,10000 do
  130.  
  131. for y = 0,10000 do
  132.  
  133. if(math.equalOffset(x/y, oldNum)) then
  134.  
  135. chisl = x
  136.  
  137. znam = y
  138.  
  139. foundNeed = true;
  140.  
  141. break;
  142.  
  143. end
  144.  
  145. if(foundNeed) then break; end
  146.  
  147. end
  148.  
  149. end
  150.  
  151. local nod = math.nod(chisl, znam)
  152.  
  153. if(nod and nod > 1) then
  154.  
  155. znam = znam / nod;
  156.  
  157. chisl = chisl / nod;
  158.  
  159. end
  160.  
  161. if((math.isInt(chisl) and math.isInt(znam)) or smesh or true) then
  162.  
  163. if(smesh) then
  164.  
  165. if(onlyNum) then
  166.  
  167. return isNegative .. " " .. celoe;
  168.  
  169. else
  170.  
  171. return addition .. isNegative .. " " .. celoe;
  172.  
  173. end
  174.  
  175. else
  176.  
  177. local tires = "";
  178.  
  179. for i=1,string.len(znam) do
  180.  
  181. tires = tires .. "—";
  182.  
  183. end
  184.  
  185. if(celoe > 0) then
  186.  
  187. local spaces = "";
  188.  
  189. for i=1,string.len(celoe) do
  190.  
  191. spaces = spaces .. " ";
  192.  
  193. end
  194.  
  195. if(onlyNum) then
  196.  
  197. return isNegative .. math.removeAfter(celoe) .. " " .. isNegative .. " ( " .. math.removeAfter(chisl) .. " / " .. math.removeAfter(znam) .. " )"
  198.  
  199. else
  200.  
  201. return "\n " .. spaces .. math.removeAfter(chisl) .. "\n" .. addition .. isNegative .. " " .. math.removeAfter(celoe) .. " ——" .. tires .. "\n " .. spaces .. math.removeAfter(znam) .. "\n\n" .. "\n" .. addition .. num
  202.  
  203. end
  204.  
  205. else
  206.  
  207. if(onlyNum) then
  208.  
  209. return isNegative .. " ( " .. math.removeAfter(chisl) .. " / " .. math.removeAfter(znam) .. " )"
  210.  
  211. else
  212.  
  213. return "\n " .. math.removeAfter(chisl) .. "\n" .. addition .. isNegative .. " ——" .. tires .. "\n " .. math.removeAfter(znam) .. "\n\n" .. "\n" .. addition .. num;
  214.  
  215. end
  216.  
  217. end
  218.  
  219. end
  220.  
  221. else
  222.  
  223. if(onlyNum) then
  224.  
  225. return num;
  226.  
  227. else
  228.  
  229. return "\n" .. addition .. num;
  230.  
  231. end
  232.  
  233. end
  234.  
  235. end
  236.  
  237. function round(num, numDecimalPlaces)
  238. if numDecimalPlaces and numDecimalPlaces>0 then
  239. local mult = 10^numDecimalPlaces
  240. return math.floor(num * mult + 0.5) / mult
  241. end
  242. return math.floor(num + 0.5)
  243. end
  244.  
  245. repeat
  246.  
  247. print(" Теперь вводим a:\n")
  248. a = io.read()
  249. print(" Теперь вводим b:\n")
  250. b = io.read()
  251. print(" Теперь вводим c:\n")
  252. c = io.read()
  253. D = (b*b) - (4*a*c)
  254. print("\n———————————————————————————————————————————————\n")
  255. print(" Способ 1.")
  256. print("\n———————————————————————————————————————————————\n")
  257. print("\n ФОРМУЛЫ\n")
  258. print("\n D = b² - 4ac\n")
  259.  
  260. sqrtOld = math.sqrt(math.abs(D))
  261.  
  262. if(math.isFloat(sqrtOld)) then sqrt = math.findCommon(sqrtOld, true) end;
  263.  
  264. if(D > 0) then
  265. print("\n -b - √D")
  266. print(" x1 = —————————")
  267. print(" 2a\n")
  268. print(" -b + √D")
  269. print(" x2 = —————————")
  270. print(" 2a")
  271. x1 = ((b*-1)-sqrtOld)/(2*a)
  272. x2 = ((b*-1)+sqrtOld)/(2*a)
  273. print("\n\n РЕШЕНИЕ\n\n")
  274. print(" D = " .. b .. "² - 4*" .. a .. "*" .. c)
  275. print(" D = " .. b*b .. " - " .. 4*a*c)
  276. print("\n D = " .. D)
  277. print("\n " .. b*-1 .. " - √" .. D)
  278. print(" x1 = ————————————————————")
  279. if(a == 1) then
  280. print(" " .. a)
  281. else
  282. print(" 2 * " .. a)
  283. end
  284. print("\n " .. b*-1 .. " - " .. sqrtOld)
  285. print(" x1 = ————————————————————")
  286. print(" " .. 2*a)
  287. print(math.findCommon(x1, false, " x1 = "))
  288. print("\n\n " .. b*-1 .. " + √" .. D)
  289. print(" x2 = ————————————————————")
  290. if(a == 1) then
  291. print(" " .. a)
  292. else
  293. print(" 2 * " .. a)
  294. end
  295. print("\n " .. b*-1 .. " + " .. sqrtOld)
  296. print(" x2 = ————————————————————")
  297. print(" " .. 2*a)
  298. print(math.findCommon(x2, false, " x2 = "))
  299. print("\n\n ОТВЕТ: " .. math.findCommon(x1, true) .. "; " .. math.findCommon(x2, true))
  300.  
  301. print("\n———————————————————————————————————————————————\n")
  302. print(" Способ 2.")
  303. print("\n———————————————————————————————————————————————\n")
  304. print("\n ФОРМУЛЫ\n")
  305. x1 = (b/2)*-1+math.sqrt(math.abs((b/2)^2-c))
  306. x2 = (b/2)*-1-math.sqrt(math.abs((b/2)^2-c))
  307. print("\n p")
  308. print(" x1 = - ——— + √(p/2)²-q")
  309. print(" 2\n")
  310. print("\n p")
  311. print(" x2 = - ——— - √(p/2)²-q")
  312. print(" 2\n")
  313. print("\n\n РЕШЕНИЕ\n\n")
  314. print("\n " .. b)
  315. print(" x1 = - ——— - √(" .. b .. "/2)²-" .. c)
  316. print(" 2")
  317. print("\n x1 = " .. b/2*-1 .. " - √(" .. b/2 .. ")²-" .. c)
  318. print(math.findCommon(x1, false, " x1 = "))
  319. print("\n " .. b)
  320. print(" x2 = - ——— + √(" .. b .. "/2)²-" .. c)
  321. print(" 2")
  322. print("\n x2 = " .. b/2*-1 .. " + √(" .. b/2 .. ")²-" .. c)
  323. print(math.findCommon(x2, false, " x2 = "))
  324. print("\n\n ОТВЕТ: " .. math.findCommon(x1, true) .. "; " .. math.findCommon(x2, true))
  325.  
  326. if(math.fmod(b, 2) == 0) then
  327.  
  328. print("\n———————————————————————————————————————————————\n")
  329. print(" Способ 3.")
  330. print("\n———————————————————————————————————————————————\n")
  331. print("\n ФОРМУЛЫ\n")
  332. k = b/2
  333. x1 = ((k*-1)+math.sqrt(k^2-a*c))/a;
  334. x2 = ((k*-1)-math.sqrt(k^2-a*c))/a;
  335. print("\n -k+√(k²-ac)")
  336. print(" x1 = ————————")
  337. print(" a\n")
  338. print("\n -k-√(k²-ac)")
  339. print(" x2 = ————————")
  340. print(" a\n")
  341. print("\n\n РЕШЕНИЕ\n\n")
  342. print("\n " .. k*-1 .. " + √(" .. k .. "²-" .. a .. "*" .. c .. ")")
  343. print(" x1 = ———————————")
  344. print(" " .. a .. "\n")
  345. print("\n x1 = ( " .. k*-1 .. " + √ ( " .. k^2 .. " - " .. a*c .. " ) ) / " .. a)
  346. print(math.findCommon(x1, false, " x1 = "))
  347. print("\n " .. k*-1 .. " - √(" .. k .. "²-" .. a .. "*" .. c .. ")")
  348. print(" x2 = ———————————")
  349. print(" " .. a .. "\n")
  350. print("\n x2 = ( " .. k*-1 .. " - √ ( " .. k^2 .. " - " .. a*c .. " ) ) / " .. a)
  351. print(math.findCommon(x2, false, " x2 = "))
  352. print("\n\n ОТВЕТ: " .. math.findCommon(x1, true) .. "; " .. math.findCommon(x2, true))
  353.  
  354. end
  355.  
  356. elseif(D < 0) then
  357. print("\n\n РЕШЕНИЕ\n\n")
  358. print(" D = " .. b .. "² - 4*" .. a .. "*" .. c)
  359. print(" D = " .. b*b .. " - " .. 4*a*c)
  360. print("\n D = " .. D)
  361. print("\n\n корней нет.")
  362. print("\n\n ОТВЕТ: корней нет.")
  363. elseif(D == 0) then
  364. print("\n -b")
  365. print(" x = ———————")
  366. print(" 2a\n")
  367. print("\n\n РЕШЕНИЕ\n\n")
  368. print(" D = " .. b .. "² - 4*" .. a .. "*" .. c)
  369. print(" D = " .. b*b .. " - " .. 4*a*c)
  370. print("\n D = " .. D)
  371. print("\n " .. b*-1)
  372. print(" x = ————————————")
  373. if(a == 1) then
  374. print(" " .. a)
  375. else
  376. print(" 2 * " .. a)
  377. end
  378. x = round((b*-1)/(2*a), 3)
  379. print("\n x = " .. math.findCommon(x, true))
  380. print("\n\n ОТВЕТ: " .. math.findCommon(x, true))
  381. --print(" " .. b*-1 .. "\nx = —————————————————— = " .. x .. " \n " .. 2*a .. "\n")
  382. end
  383. print("\n———————————————————————————————————————————————\n\n\n")
  384.  
  385. until 0 == 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement