Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Noble Gas Notation by mortonfox
ATOMIC_NUMBERS = {
'H': 1,
'He': 2,
'Li': 3,
'O': 8,
'Ne': 10,
'Na': 11,
'Al': 13,
'Cl': 17,
'Ar': 18,
'K': 19,
'V': 23,
'Br': 35,
'Kr': 36,
'Rb': 37,
'In': 49,
'I': 53,
'Xe': 54,
'Ir': 77,
'Tl': 81,
'Rn': 86,
'Fr': 87,
'Db': 105,
'Ds': 110,
'Ts': 117,
'Og': 118,
}
NOBLE_GASES = ['He', 'Ne', 'Ar', 'Kr', 'Xe', 'Rn', 'Og']
ORBITAL_CAPACITIES = {'s': 2, 'p': 6, 'd': 10, 'f': 14}
ORBITS = [ '1s', '2s', '2p', '3s', '3p', '4s', '3d', '4p', '5s', '4d', '5p', '6s', '4f', '5d', '6p', '7s', '5f', '6d', '7p' ]
def notation(element: str) -> str:
n = ATOMIC_NUMBERS[element]
res = []
nbl = 0
for gas in NOBLE_GASES[::-1]:
if ATOMIC_NUMBERS[gas] < n:
nbl = ATOMIC_NUMBERS[gas]
n -= nbl
res.append(f'[{gas}]')
break
for orbit in ORBITS:
el = ORBITAL_CAPACITIES[orbit[1]]
if nbl > 0:
nbl -= el
elif n > 0:
nel = min(el, n)
res.append(f'{orbit}{nel}')
n -= nel
return ' '.join(res[:1] + sorted(res[1:], key=lambda s: (s[0], ORBITAL_CAPACITIES[s[1]])))
print("Example:")
print(notation("He"))
# These "asserts" are used for self-checking
assert notation("H") == "1s1"
assert notation("He") == "1s2"
assert notation("Al") == "[Ne] 3s2 3p1"
assert notation("O") == "[He] 2s2 2p4"
assert notation("Li") == "[He] 2s1"
assert notation('Og') == '[Rn] 5f14 6d10 7s2 7p6'
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 24, 2025
Comments: