Advertisement
BobMe

CHEEEEEEEEEEEEEEEEEEEEM

Dec 6th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. local percents = {26.7,12.1,61.2}
  2. local grams = {}
  3. local weight = {30.973761,14.00674,35.4527}
  4. local name = {"P","N","Cl"}
  5. local vals = {1,1,2}
  6.  
  7. local times_by = 1
  8.  
  9. function round(number,deci)
  10. local num = tostring(number)
  11. local num2 = ""
  12. local num3 = ""
  13. local num4
  14. local savevar1 = ""
  15. for i=1,#num do
  16. if string.sub(num,i,i+1):lower() == "e+" then
  17. savevar1 = string.sub(num,i+2)
  18. num2 = string.sub(num,1,i-1)
  19. break
  20. end
  21. end
  22. if num2 ~= "" then num = num2 end
  23. for i=1,#num do
  24. if string.sub(num,i,i) == "." then
  25. num3 = tonumber(string.sub(num,deci+i+1,deci+i+1))
  26. num4 = tonumber(string.sub(num,deci+i,deci+i))
  27. if num3 == "" or num3 == nil then break end
  28. if num3 >= 5 then
  29. num = string.sub(num,1,i-1+deci)..tostring(num4+1)
  30. else
  31. num = string.sub(num,1,i-1+deci)..tostring(num4)
  32. end
  33. end
  34. end
  35. if savevar1 ~= "" then
  36. num = num.." * 10"..supernumbers(savevar1)
  37. end
  38. return num
  39. end
  40.  
  41. function roundwhole(x)
  42. local y = tostring(x)
  43. for i=1,#y do
  44. if string.sub(y,i,i) == "." then
  45. local num1 = tonumber(string.sub(y,i-1,i-1))
  46. local num2 = tonumber(string.sub(y,i+1,i+1))
  47. if num2 >= 5 then
  48. num1 = num1 + 1
  49. end
  50. return tonumber(string.sub(y,1,i-2)..num1)
  51. end
  52. end
  53. end
  54.  
  55. for i=1,#percents do
  56. local tek = percents[i] * (1/weight[i])
  57. table.insert(grams,tek)
  58. end
  59.  
  60. local j = grams[1]
  61. local sav = {}
  62. for i=1,#grams do
  63. print(name[i].." | "..grams[i])
  64. if grams[i] < j then
  65. j = grams[i]
  66. end
  67. end
  68. print("--------------------------------")
  69. print("Moles: "..j)
  70. print("--------------------------------")
  71. local g = 0
  72. for i=1,#weight do
  73. g = g + (weight[i]*vals[i])
  74. end
  75. print("Empirical Molar Mass: "..round(g,1))
  76. print("--------------------------------")
  77. for i=1,#grams do
  78. table.insert(sav,round((grams[i]/j)--[[*times_by]],1))
  79. end
  80.  
  81. for i=1,#sav do
  82. print(name[i].." | "..sav[i]*times_by)
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement