Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
straightforward ... solution in Clear category for Noble Gas Notation by maybe
ATOMIC_NUMBERS = {
"H": 1,
"He": 2,
"Li": 3,
"O": 8,
"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,
"Uus": 117,
"Uuo": 118,
}
# NOBLE_GASES = ["He", "Ne", "Ar", "Kr", "Xe", "Rn", "Uuo"]
# ORBITAL_CAPACITIES = {"s": 2, "p": 6, "d": 10, "f": 14}
NOBLE_GASES = {"He":2, "Ne":10, "Ar":18, "Kr":36, "Xe":54, "Rn":86, "Uuo":118}
from collections.abc import Iterator
from collections import Counter
type Orbtype = tuple[int,int] # orbital as (n,l)-tuple
def orb_in_fill_order() -> Iterator[Orbtype]:
"""Generator for orbitals ordered by Klechkowski's rule."""
n_l = 1
while ...:
for l in range((n_l - 1) // 2, -1, -1):
yield (n_l - l, l)
n_l += 1
def get_config(charge: int) -> Counter[Orbtype]:
"""Get distribution of charge into orbitals."""
orbs = Counter()
for (n,l) in orb_in_fill_order():
cap = 2 + l*4
orbs[(n,l)] = min(cap, charge)
charge -= cap
if charge <= 0: break
return orbs
def notation(element: str) -> str:
if element == "H": return "1s1"
if element == "He": return "1s2"
echarge = ATOMIC_NUMBERS[element]
ecfg = get_config(echarge)
ncharge, nname = max((charge, name) for name, charge in NOBLE_GASES.items() if charge < echarge)
ncfg = get_config(ncharge)
def fmtfun(arg):
(n,l), c = arg # would prefer 'lambda' over 'def', but how to do this unpacking?
return f"{n}{"spdfgh"[l]}{c}"
return f"[{nname}] " + ' '.join(map(fmtfun, sorted((ecfg-ncfg).items()) ))
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"
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 20, 2025
Comments: