Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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
- -- write a script to force the computer to do it for me instead. Is that too evil? I think not.
- local tab = {"1s","2s","2p","3s","3p","4s","3d","4p","5s","4d","5p","6s","4f","5d","6p","7s","5f","6d","7p","6f","7d","7f"}
- electrons = 71 -- 156 is the largest number you can calculate
- function define(x)
- local k = string.sub(x,2,2)
- if k == "s" then
- return 2
- elseif k == "p" then
- return 6
- elseif k == "d" then
- return 10
- elseif k == "f" then
- return 14
- end
- end
- function tosuperscript(x)
- local sup = {"⁰","¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹","¹⁰","¹¹","¹²","¹³","¹⁴","¹⁵","¹⁶","¹⁷","¹⁸","¹⁹"}
- return sup[x+1]
- end
- local out = ""
- for i=1,#tab do
- local k = define(tab[i])
- local sum = electrons - k
- if sum > 0 then
- electrons = electrons - k
- out = out..tab[i]..tosuperscript(k).." "
- else
- local newsum = electrons -- problems may orginate from here
- out = out..tab[i]..tosuperscript(newsum).." "
- break
- end
- end
- print(out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement