Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Quasiperiodic solution in Clear category for Periodic Table by veky
import collections
SYMBOLS = str.split('''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''')
DIGITS = dict(enumerate('⁰¹²³⁴⁵⁶⁷⁸⁹', start=ord('0')))
Level = collections.namedtuple('Level', 'shell orbital')
Level.full = lambda self: 4 * self.orbital + 2
ORBS = [Level(p-l, l) for p in range(9) for l in reversed(range(9)) if p-l > l]
LEVELS = [level for level in ORBS for repeat in range(level.full())]
EXCEPTIONS = [(24,5), (29,5), (41,8), (42,8), (44,8), (45,8), (46,8), (46,8),
(47,8), (57,12), (58,12), (64,12), (78,11), (78,12), (79,11), (79,12),
(89,16), (90,16), (90,16), (91,16), (92,16), (93,16), (96,16), (103,17)]
def fill(n, level):
half = level.full() // 2
slots = bytearray(b'0' * half)
for electron in range(n): slots[electron % half] += 1
return slots.decode()
def condensed(n, level):
return str(level.shell) + 'spdf'[level.orbital] + str(n).translate(DIGITS)
def layout(electrons, count, orbs):
return ' '.join(electrons(count[orb], orb) for orb in orbs if count[orb])
def electron_classifier(atomic_number):
return collections.Counter(LEVELS[:atomic_number])
def checkio(symbol):
atomic_number = SYMBOLS.index(symbol) + 1
count = electron_classifier(atomic_number)
noble = LEVELS.index(max(level for level in count if not level.orbital))
for exceptional, orbital in EXCEPTIONS:
if atomic_number == exceptional: # hop 1e to the next orbital
count[ORBS[orbital ]] -= 1
count[ORBS[orbital+1]] += 1
conf = layout(condensed, count - electron_classifier(noble), sorted(ORBS))
if noble: conf = f'[{SYMBOLS[noble-1]}] {conf}'
return str(atomic_number), conf, layout(fill, count, ORBS)
July 22, 2017
Comments: