Skip to main content
Tweeted twitter.com/StackCodeGolf/status/1294423680722886657
fix test cases
Source Link
golf69
  • 2.1k
  • 1
  • 15
  • 31

The periodic table gets its shape from the arrangement of elements into blocks:

blocks intro

An element is assigned its block based on what type of orbital holds its valence electron(s). For instance, the sole valence electron of neutral hydrogen occupies the 1s orbital in the 1s subshell, and so hydrogen belongs to the s-block.

The least energetic subshell is the 1s subshell, followed by 2s, 2p, 3s, etc. Electrons fill orbitals in less-energetic subshells first, in accordance with the following chart:

arrow

The diagonal arrows give the diagonal rule its name.

When finding the block of an element, there are some important facts to consider:

  • Each subsequent element has one more electron than its predecessor.

  • Every new type of subshell (s, p, d . . . ) can hold four more electrons than its predecessor as a consequence of the presence of two additional orbitals.

  • All subshells (1s, 2s . . . ) have an odd number of orbitals, each of which can hold two electrons. As such, all subshells can hold twice an odd number of electrons.

  • Subshells beyond s, p, d and f have names reserved for their eventual observation: after f comes the rest of the alphabet, starting with g and omitting j.

The Challenge

Given the atomic number of an element, output its block (a letter).

Because one can tell how many electrons are held by theorized, not-yet-observed subshells, input will be less than or equal to 17296 (found with the sum \$2\sum_{n=1}^{23}\sum_{\ell=0}^{n-1}2\left(2\ell+1\right)\$), the atomic number of the last element with valence electrons in the 46s subshell. Letters beyond z would be needed for elements past that point, and so they will not be included in the challenge. An extended version of the diagonal line chart above can be seen here.

Rules

  • This is so the shortest answer in bytes in each language wins

  • For the purpose of this challenge, when s and p are reached a second time after f, they will be capitalized. This means letters are sequenced as follows: s p d f g h i k l m n o P q r S t u v w x y z. Additionally, it means output is case-sensitive.

  • Assume only valid input is given.

  • There is a discrepancy between the periodic table above and the expected output: in reality, lanthanum and actinium (57 and 89) are in the d-block, and lutetium and lawrencium (71 and 103) are in the f-block. The diagonal rule implies that lanthanum and actinium are in the f-block, and that lutetium and lawrencium are in the d-block, and so that is what the program should state.

Test Cases

In: 1
Out: s

In: 5
Out: p

In: 21
Out: d

In: 57
Out: f

In: 2784
Out: ml

In: 17296
Out: s

In: 15181
Out: z

In: 12024
Out: P (capitalized)q

The periodic table gets its shape from the arrangement of elements into blocks:

blocks intro

An element is assigned its block based on what type of orbital holds its valence electron(s). For instance, the sole valence electron of neutral hydrogen occupies the 1s orbital in the 1s subshell, and so hydrogen belongs to the s-block.

The least energetic subshell is the 1s subshell, followed by 2s, 2p, 3s, etc. Electrons fill orbitals in less-energetic subshells first, in accordance with the following chart:

arrow

The diagonal arrows give the diagonal rule its name.

When finding the block of an element, there are some important facts to consider:

  • Each subsequent element has one more electron than its predecessor.

  • Every new type of subshell (s, p, d . . . ) can hold four more electrons than its predecessor as a consequence of the presence of two additional orbitals.

  • All subshells (1s, 2s . . . ) have an odd number of orbitals, each of which can hold two electrons. As such, all subshells can hold twice an odd number of electrons.

  • Subshells beyond s, p, d and f have names reserved for their eventual observation: after f comes the rest of the alphabet, starting with g and omitting j.

The Challenge

Given the atomic number of an element, output its block (a letter).

Because one can tell how many electrons are held by theorized, not-yet-observed subshells, input will be less than or equal to 17296 (found with the sum \$2\sum_{n=1}^{23}\sum_{\ell=0}^{n-1}2\left(2\ell+1\right)\$), the atomic number of the last element with valence electrons in the 46s subshell. Letters beyond z would be needed for elements past that point, and so they will not be included in the challenge. An extended version of the diagonal line chart above can be seen here.

Rules

  • This is so the shortest answer in bytes in each language wins

  • For the purpose of this challenge, when s and p are reached a second time after f, they will be capitalized. This means letters are sequenced as follows: s p d f g h i k l m n o P q r S t u v w x y z. Additionally, it means output is case-sensitive.

  • Assume only valid input is given.

  • There is a discrepancy between the periodic table above and the expected output: in reality, lanthanum and actinium (57 and 89) are in the d-block, and lutetium and lawrencium (71 and 103) are in the f-block. The diagonal rule implies that lanthanum and actinium are in the f-block, and that lutetium and lawrencium are in the d-block, and so that is what the program should state.

Test Cases

In: 1
Out: s

In: 5
Out: p

In: 21
Out: d

In: 57
Out: f

In: 2784
Out: m

In: 17296
Out: s

In: 15181
Out: z

In: 12024
Out: P (capitalized)

The periodic table gets its shape from the arrangement of elements into blocks:

blocks intro

An element is assigned its block based on what type of orbital holds its valence electron(s). For instance, the sole valence electron of neutral hydrogen occupies the 1s orbital in the 1s subshell, and so hydrogen belongs to the s-block.

The least energetic subshell is the 1s subshell, followed by 2s, 2p, 3s, etc. Electrons fill orbitals in less-energetic subshells first, in accordance with the following chart:

arrow

The diagonal arrows give the diagonal rule its name.

When finding the block of an element, there are some important facts to consider:

  • Each subsequent element has one more electron than its predecessor.

  • Every new type of subshell (s, p, d . . . ) can hold four more electrons than its predecessor as a consequence of the presence of two additional orbitals.

  • All subshells (1s, 2s . . . ) have an odd number of orbitals, each of which can hold two electrons. As such, all subshells can hold twice an odd number of electrons.

  • Subshells beyond s, p, d and f have names reserved for their eventual observation: after f comes the rest of the alphabet, starting with g and omitting j.

The Challenge

Given the atomic number of an element, output its block (a letter).

Because one can tell how many electrons are held by theorized, not-yet-observed subshells, input will be less than or equal to 17296 (found with the sum \$2\sum_{n=1}^{23}\sum_{\ell=0}^{n-1}2\left(2\ell+1\right)\$), the atomic number of the last element with valence electrons in the 46s subshell. Letters beyond z would be needed for elements past that point, and so they will not be included in the challenge. An extended version of the diagonal line chart above can be seen here.

Rules

  • This is so the shortest answer in bytes in each language wins

  • For the purpose of this challenge, when s and p are reached a second time after f, they will be capitalized. This means letters are sequenced as follows: s p d f g h i k l m n o P q r S t u v w x y z. Additionally, it means output is case-sensitive.

  • Assume only valid input is given.

  • There is a discrepancy between the periodic table above and the expected output: in reality, lanthanum and actinium (57 and 89) are in the d-block, and lutetium and lawrencium (71 and 103) are in the f-block. The diagonal rule implies that lanthanum and actinium are in the f-block, and that lutetium and lawrencium are in the d-block, and so that is what the program should state.

Test Cases

In: 1
Out: s

In: 5
Out: p

In: 21
Out: d

In: 57
Out: f

In: 2784
Out: l

In: 17296
Out: s

In: 15181
Out: z

In: 12024
Out: q
Source Link
golf69
  • 2.1k
  • 1
  • 15
  • 31

Find the Block on the Extended Periodic Table Using the Diagonal Rule

The periodic table gets its shape from the arrangement of elements into blocks:

blocks intro

An element is assigned its block based on what type of orbital holds its valence electron(s). For instance, the sole valence electron of neutral hydrogen occupies the 1s orbital in the 1s subshell, and so hydrogen belongs to the s-block.

The least energetic subshell is the 1s subshell, followed by 2s, 2p, 3s, etc. Electrons fill orbitals in less-energetic subshells first, in accordance with the following chart:

arrow

The diagonal arrows give the diagonal rule its name.

When finding the block of an element, there are some important facts to consider:

  • Each subsequent element has one more electron than its predecessor.

  • Every new type of subshell (s, p, d . . . ) can hold four more electrons than its predecessor as a consequence of the presence of two additional orbitals.

  • All subshells (1s, 2s . . . ) have an odd number of orbitals, each of which can hold two electrons. As such, all subshells can hold twice an odd number of electrons.

  • Subshells beyond s, p, d and f have names reserved for their eventual observation: after f comes the rest of the alphabet, starting with g and omitting j.

The Challenge

Given the atomic number of an element, output its block (a letter).

Because one can tell how many electrons are held by theorized, not-yet-observed subshells, input will be less than or equal to 17296 (found with the sum \$2\sum_{n=1}^{23}\sum_{\ell=0}^{n-1}2\left(2\ell+1\right)\$), the atomic number of the last element with valence electrons in the 46s subshell. Letters beyond z would be needed for elements past that point, and so they will not be included in the challenge. An extended version of the diagonal line chart above can be seen here.

Rules

  • This is so the shortest answer in bytes in each language wins

  • For the purpose of this challenge, when s and p are reached a second time after f, they will be capitalized. This means letters are sequenced as follows: s p d f g h i k l m n o P q r S t u v w x y z. Additionally, it means output is case-sensitive.

  • Assume only valid input is given.

  • There is a discrepancy between the periodic table above and the expected output: in reality, lanthanum and actinium (57 and 89) are in the d-block, and lutetium and lawrencium (71 and 103) are in the f-block. The diagonal rule implies that lanthanum and actinium are in the f-block, and that lutetium and lawrencium are in the d-block, and so that is what the program should state.

Test Cases

In: 1
Out: s

In: 5
Out: p

In: 21
Out: d

In: 57
Out: f

In: 2784
Out: m

In: 17296
Out: s

In: 15181
Out: z

In: 12024
Out: P (capitalized)