Advertisement
BobMe

Magic Number Calculator

Apr 23rd, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. -- I initially used Microsoft Exel to use this, but because of it's limitations I turned it into a nicer and better script. If you do not know what magic numbers are, don't bother with this script. If you do, you will find this very useful.
  2.  
  3. function round(number)
  4. kek = nil
  5. local strnum = tostring(number)
  6. for i=1,#strnum do
  7. if string.sub(strnum,i,i) == "." then
  8. kek = tonumber(string.sub(strnum,i+1,i+1))
  9. kek2 = tonumber(string.sub(strnum,1,i-1))
  10. end
  11. end
  12. if kek ~= nil then
  13. if kek >= 5 then
  14. kek2 = kek2 + 1
  15. else
  16. kek2 = kek2
  17. end
  18. end
  19. return kek2
  20. end
  21.  
  22. function removedec(number)
  23. kek = number
  24. local strnum = tostring(number)
  25. for i=1,#strnum do
  26. if string.sub(strnum,i,i) == "." and string.sub(strnum,i+1,i+1) == "0" and string.sub(strnum,i+2,i+2) == "" then
  27. kek = tonumber(string.sub(strnum,1,i-1))
  28. end
  29. end
  30. return kek
  31. end
  32.  
  33. function notdec(number)
  34. kek = false
  35. local strnum = tostring(number)
  36. for i=1,#strnum do
  37. if string.sub(strnum,i,i) == "." and string.sub(strnum,i+1,i+1) == "0" and string.sub(strnum,i+2,i+2) == "" then
  38. kek = true
  39. end
  40. end
  41. return kek
  42. end
  43.  
  44.  
  45. function findmagicnumbers(a,b,c)
  46. neg = false
  47. local sum = a*c
  48. if sum < 0 then
  49. neg = true
  50. sum = sum * -1
  51. end
  52. local aon = round(math.sqrt(sum))
  53. for i=1,aon do
  54. local ssum = sum/i
  55. if neg == true then
  56. i = i*-1
  57. end
  58. if b < 0 then
  59. ssum = ssum*-1
  60. --if neg ~= true then
  61. i = i*-1
  62. -- end
  63. end
  64. if --[[neg]]false == false then
  65. if notdec(ssum) == true then
  66. if ssum + i == b then
  67. print("ANS//"..i.." | "..ssum)
  68. sssum = {i,ssum}
  69. else
  70. print(" "..i.." | "..ssum)
  71. end
  72. elseif notdec(ssum) == false then
  73. print("N "..i.." | "..ssum)
  74. end
  75. end
  76. end
  77. if sssum ~= nil then
  78. print("------------------------------------\nANSWERS:\n"..sssum[1]..", "..sssum[2])
  79. end
  80. end
  81.  
  82. findmagicnumbers(1,14,48)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement