Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- electrons = 102 -- change this number for a new element!
- subs = {2,8,18,32}
- -- Add more electron positions if our electrons fill the default ammount
- if(electrons > 60)then
- for i = 1, math.ceil((electrons - 60) / 32) do
- subs[#subs+1] = 32
- end
- end
- -- do this while we have electrons still not placed.
- while electrons > 0 do
- -- loop through the shells and try to fill them
- for i = 1, #subs do
- if(electrons >= subs[i])then
- print(subs[i])
- electrons = electrons - subs[i]
- else -- if the electrons doesnt fill the shell then,
- -- if we have less than or equal too 8 electrons left (max valence electrons)
- -- then place them all down.
- if(electrons <= 8 and electrons > 0)then
- print(electrons)
- electrons= 0
- end
- -- look backwards through the table and search through previous shells
- -- so electrons that didnt get a chance to get placed are now placed.
- for y = #subs, 1, -1 do
- if(electrons >= subs[y] and electrons > 0)then
- print(subs[y])
- electrons = electrons - subs[y]
- end
- end
- -- if the backwards loop couldnt find a place for some electrons then place the rest down.
- -- the backwards loop cannot fail, if it does then there is less than 2 electrons left.
- if(electrons > 0)then
- print(electrons)
- electrons = 0
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement