Posted 19 May 2016 - 03:09 AM
I am currently working on a atom structure calculator which only takes an atoms atomic number to generate its structure,
for the most part it works but there are some things it doesnt work on. the reason i want to calculate the atoms instead of have them pre-setup is because
i eventually want to make a molecule simulator.
now what i mean by doesnt work with some atoms is that some atoms have strange numbers of electrons in their shells like for instance,
22 or 16 or 14 or 30 or even 28. not sure if theres a pattern to these, so thats what i need help figuring out,
thanks.
heres the pastebin link - http://pastebin.com/gckNFraD
i made a smaller more refined and commented version for those of you that are confused:
for the most part it works but there are some things it doesnt work on. the reason i want to calculate the atoms instead of have them pre-setup is because
i eventually want to make a molecule simulator.
now what i mean by doesnt work with some atoms is that some atoms have strange numbers of electrons in their shells like for instance,
22 or 16 or 14 or 30 or even 28. not sure if theres a pattern to these, so thats what i need help figuring out,
thanks.
heres the pastebin link - http://pastebin.com/gckNFraD
i made a smaller more refined and commented version for those of you that are confused:
Spoiler
electrons = 102
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
Edited on 21 May 2016 - 12:11 PM