Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using a lookup-table for the n+l orbitals solution in Clear category for Noble Gas Notation by Mysta
from typing import List
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}
NL_TABLE: List[str] = [
"1s",
"2s",
"2p",
"3s",
"3p",
"4s",
"3d",
"4p",
"5s",
"4d",
"5p",
"6s",
"4f",
"5d",
"6p",
"7s",
"5f",
"6d",
"7p", # The mission is not intended to handle elements with higher values!
]
# -----------------------------------------------------------------------------
def notation(element: str) -> str:
electrons: int = ATOMIC_NUMBERS[element]
nl_idx: int = 0 # At the beginning point to the "1s" orbital
noble_gas_core: str = ""
for noble_gas in NOBLE_GASES[::-1]:
if (numbers := ATOMIC_NUMBERS[noble_gas]) < electrons:
# Build the nobel gas prefix for the result notation string
noble_gas_core = f"[{noble_gas}] "
# Reduce the number of electrons covered by that noble gas
electrons -= numbers
# Adjust the index to the next lowest n+l orbital
nl_idx = NL_TABLE.index(str(NOBLE_GASES.index(noble_gas) + 2) + "s")
break
terms: List[str] = [] # will contain all filled n+l orbitals
while electrons > 0:
nl: str = NL_TABLE[nl_idx] # Get the next n+l orbital (e.g. "2p")
# Get the number of electrons to place at that orbital
# (maximum is the capacity of the orbital, e.g. 6 for "2p")
electrons_to_place = min(ORBITAL_CAPACITIES[nl[1]], electrons)
# Build the term to be added to the notation string
terms.append(f"{nl}{electrons_to_place}")
# Reduce the remaining electrons by the number of placed electrons
electrons -= electrons_to_place
# Go to the next n+l orbital
nl_idx += 1
# The orbitals have to sorted by the n orbital!
return noble_gas_core + " ".join(sorted(terms, key=lambda i: i[0]))
March 14, 2026
Comments: