Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Finally ! solution in Uncategorized category for Periodic Table by Juge_Ti
def checkio(element):
nb_elec_in_orb = lambda orb: orbitals.index(orb[1])*4 + 2
elements = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na',
'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti',
'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge',
'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo',
'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te',
'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm',
'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf',
'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb',
'Bi', 'Po', 'At', 'Rn', 'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U',
'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No',
'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn',
'Uut', 'Fl', 'Uup', 'Lv', 'Uus', 'Uuo']
exceptions = {'Cr': (1,5), 'Cu': (1,10), 'Nb': (1,4), 'Mo': (1,5),
'Ru': (1,7), 'Rh': (1,8), 'Pd': (0,10), 'Ag': (1,10),
'La': (2,0,1), 'Ce': (2,1,1), 'Gd': (2,7,1), 'Pt': (1,14,9),
'Au': (1,14,10), 'Ac': (2,0,1), 'Th': (2,0,2), 'Pa': (2,2,1),
'U': (2,3,1), 'Np': (2,4,1), 'Cm': (2,7,1), 'Lr': (2,14,0,1)}
orbitals = ['s', 'p', 'd', 'f', 'g', 'h', 'i', 'j']
noble = ['', '[He]', '[Ne]', '[Ar]', '[Kr]', '[Xe]', '[Rn]']
Znoble = [0, 2, 10, 18, 36, 54, 86]
sup = {0: '\u2070', 1: '\u00B9', 2: '\u00B2', 3: '\u00B3', 4: '\u2074',
5: '\u2075', 6: '\u2076', 7: '\u2077', 8: '\u2078', 9: '\u2079'}
L = [str(n) + orbitals[l] for n, l in sorted([(n, l) for n in range(1, 8)
for l in range(n)], key=sum)]
Z = elements.index(element) + 1
n = max(x for x in range(7) if Znoble[x] < Z) + 1
config = ''
orbital_model = ''
k = L.index(str(n)+'s')
total = 0
for j, orb in enumerate(L):
if total == Z:
break
p = nb_elec_in_orb(orb) // 2
if element not in exceptions or j < k:
for electron in range(2*p):
total += 1
if total == Z:
break
else:
electron = exceptions[element][j-k] - 1
total += electron + 1
if electron + 1:
orbital_model += ''.join(str(electron//p + (i <= electron%p))
for i in range(p)) + ' '
if j >= k:
new = orb + ''.join(sup[int(x)] for x in str(electron +1))
if 's' in orb or 'p' in orb:
config += ' ' + new
elif 'f' in orb:
config = ' ' + new + config
else:
i = config.index('s')
config = config[:i-1] + new + ' ' + config[i-1:]
return [str(Z), (noble[n-1] + config).lstrip(), orbital_model.rstrip()]
Sept. 27, 2013
Comments: