Advertisement
BobMe

Atomic Number chemistry counter thing

Oct 8th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. -- In chemistry class, we were forced to count the number of electrons in certain atoms using a weird old scientist man techinque, so I decided to
  2. -- write a script to force the computer to do it for me instead. Is that too evil? I think not.
  3.  
  4. local tab = {"1s","2s","2p","3s","3p","4s","3d","4p","5s","4d","5p","6s","4f","5d","6p","7s","5f","6d","7p","6f","7d","7f"}
  5. electrons = 71 -- 156 is the largest number you can calculate
  6.  
  7. function define(x)
  8. local k = string.sub(x,2,2)
  9. if k == "s" then
  10. return 2
  11. elseif k == "p" then
  12. return 6
  13. elseif k == "d" then
  14. return 10
  15. elseif k == "f" then
  16. return 14
  17. end
  18. end
  19.  
  20. function tosuperscript(x)
  21. local sup = {"⁰","¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹","¹⁰","¹¹","¹²","¹³","¹⁴","¹⁵","¹⁶","¹⁷","¹⁸","¹⁹"}
  22. return sup[x+1]
  23. end
  24. local out = ""
  25. for i=1,#tab do
  26. local k = define(tab[i])
  27. local sum = electrons - k
  28. if sum > 0 then
  29. electrons = electrons - k
  30. out = out..tab[i]..tosuperscript(k).." "
  31. else
  32. local newsum = electrons -- problems may orginate from here
  33. out = out..tab[i]..tosuperscript(newsum).." "
  34. break
  35. end
  36. end
  37.  
  38. print(out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement