Advertisement
BobMe

finished math thing

May 2nd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. function removedec(number)
  2. kek = number
  3. local strnum = tostring(number)
  4. for i=1,#strnum do
  5. if string.sub(strnum,i,i) == "." and string.sub(strnum,i+1,i+1) == "0" and string.sub(strnum,i+2,i+2) == "" then
  6. kek = tonumber(string.sub(strnum,1,i-1))
  7. end
  8. end
  9. return kek
  10. end
  11.  
  12. function calc(strin)
  13. if strin:sub(1,7):lower() == "x^2+y^2" then
  14. if strin:sub(8,8):lower() == "+" then
  15. neg1 = false
  16. else
  17. neg1 = true
  18. end
  19. for i=9,100 do
  20. if strin:sub(i,i):lower() == "x" then
  21. numx = string.sub(strin,9,i-1)
  22. currenti = i+1
  23. break
  24. end
  25. end
  26. if strin:sub(currenti,currenti):lower() == "+" then
  27. neg2 = false
  28. else
  29. neg2 = true
  30. end
  31. for i=currenti,200 do
  32. if strin:sub(i,i):lower() == "y" then
  33. numy = string.sub(strin,currenti+1,i-1)
  34. currenti = i+1
  35. break
  36. end
  37. end
  38. if strin:sub(currenti,currenti):lower() == "+" then
  39. neg3 = false
  40. else
  41. neg3 = true
  42. end
  43. for i=currenti,300 do
  44. if strin:sub(i,i):lower() == "=" then
  45. currenti2 = i
  46. numout = string.sub(strin,currenti+1,i-1)
  47. if string.sub(strin,currenti,currenti) == "+" then
  48. neg4 = false
  49. else
  50. neg4 = true
  51. end
  52. break
  53. end
  54. end
  55. ----
  56. nexnumber = string.sub(strin,currenti2)
  57. ----
  58. numx2 = removedec((tonumber(numx)/2)*(tonumber(numx)/2))
  59. numy2 = removedec((tonumber(numy)/2)*(tonumber(numy)/2))
  60. ----
  61. if neg1 == false then
  62. rea1 = "x² + "..numx.."x"
  63. rea2 = "x² + "..numx.."x"
  64. rea3 = "x² + "..numx.."x"
  65. rea4 = "x² + "..numx.."x + "..numx2
  66. rea5 = "(x + "..removedec((numx/2))..")²"
  67. else
  68. rea1 = "x² - "..numx.."x"
  69. rea2 = "x² - "..numx.."x"
  70. rea3 = "x² - "..numx.."x"
  71. rea4 = "x² - "..numx.."x + "..numx2
  72. rea5 = "(x - "..removedec(((numx/2)*1))..")²"
  73. end
  74. ----
  75. if neg2 == false then
  76. bea1 = "y² + "..numy.."y"
  77. bea2 = "y² + "..numy.."y"
  78. bea3 = "y² + "..numy.."y"
  79. bea4 = "y² + "..numy.."y + "..numy2
  80. bea5 = "(y + "..removedec((numy/2))..")²"
  81. else
  82. bea1 = "y² - "..numy.."y"
  83. bea2 = "y² - "..numy.."y"
  84. bea3 = "y² - "..numy.."y"
  85. bea4 = "y² - "..numy.."y + "..numy2
  86. bea5 = "(y - "..removedec(((numy/2)*1))..")²"
  87. end
  88. ----w
  89. if neg4 == false then
  90. rewrite = rea1.." + "..bea1.." + "..numout.." = 0"
  91. numout = tonumber(numout)
  92. else
  93. rewrite = rea1.." + "..bea1.." - "..numout.." = 0"
  94. numout = tonumber(numout)*-1
  95. end
  96. print(rewrite)
  97. rewrite2 = rea2.." + "..bea2.." = "..numout*-1
  98. print(rewrite2)
  99. rewrite3 = rea3.." + ___ + "..bea3.." + ___ = "..(numout*-1).." + ___ + ___"
  100. print(rewrite3)
  101. rewrite4 = rea4.." + "..bea4.." = "..(numout*-1).." + "..numx2.." + "..numy2
  102. print(rewrite4)
  103. rewrite5 = rea5.." + "..bea5.." = "..((numout*-1)+numx2+numy2)
  104. print(rewrite5)
  105.  
  106. end
  107. end
  108. calc("x^2+y^2+4x-4y+0=0")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement