Electron Configurations Electron Configurations

Your mission is to accept an element's atomic number as input, and output its electron configuration (e.g. 2,8,8,2 for calcium).

Input

An atomic number from 1 to 118. You may assume valid input. The atom is not charged (it has as many electrons as protons). You may not expect the input to be stored in a variable, and you must write a complete program.

Output

The number of electrons in each non-empty electron shell. I will be quite lenient with the output format; all of the following are acceptable, i.e. you may use any punctuation or whitespace to separate the numbers, and brackets of any sort are permitted. Please specify which is used.


2,8,8,2
2.8.8.2
2, 8, 8, 2,
[2,8,8,2]
2 8 8 2
([2 [8]] [8] 2)


How Electrons Work

In atoms, electrons are ordered into "shells", which are energy levels. Each shell has a certain capacity, the maximum number of electrons that it is capable of holding. The shells are filled from the inside out, but not evenly. Your task is to determine, given an atomic number, how many electrons there are in each shell, according to this source.

Up to and including calcium (atomic number 20), the shells fill evenly and in order; the inner shell is first filled to its capacity of 2, the second to 8, then the third to 8 and the last to 2. The electron configuration of calcium is 2,8,8,2.

After calcium, things get complicated; further electrons go into the third shell, not the last one. To make things worse, vanadium (23) is 2,8,11,2, while chromium (24) is 2,8,13,1 and manganese (25) is 2,8,13,2.

There are some consistent patterns, however: a noble gas and the seven elements before it will always have the number of electrons in the outer shell increase from 1 to 8. For example:


gold (79): 2,8,18,32,18,1
mercury (80): 2,8,18,32,18,2
...
astatine (85): 2,8,18,32,18,7
radon (86): 2,8,18,32,18,8


Rules


Standard loopholes are forbidden.
Libraries which existed prior to this challenge are permitted.
Any built-in or library features which specifically deal with atoms, molecules or chemistry are banned.
Lowest code length in bytes wins.
In the linked source, configurations of elements 103-118 are marked with (?), as they are predicted, and the elements are too unstable for this to be checked. For this challenge, assume them to be correct.
You may hardcode part or all of your data.
[NEW RULE] Please provide a base64 or an xxd dump of your files if you use control characters in them (as many answers seem to be doing)


WINNER: Dennis's CJam answer at 80 bytes!
CJam, 87 83 82 80 bytes

0"hTHøìð¼Ä¿håêÛ¾ªÔ¼"256b6b5a/4a8**li&lt;{[33:B_B*65_B*1]=\_B%8=B\#*+}/Bb0-`


The above code contains unprintable characters.

Try it online in the CJam interpreter. If the link doesn't work for you, copy from this paste.

Background

To obtain the electron configuration of the Nth atom, we start with an atom without electrons and apply N transformations to it.

To reduce the byte count of the implementation, we represent the electron configuration of an atom as an integer. Each digit of that integer in base 33 corresponds to the number of electrons in a certain shells; the least significant digit represents the outer shell.

For example, the electron configuration of Molybdenum (42) is [2 8 18 13 1]. This corresponds to the integer 2 × 334 + 8 × 333 + 18 × 332 + 13 × 33 + 1 = 26,79,370.

Palladium (48) is a special case, which we treat as [2 8 18 18 0] instead of [2 8 18 18].

This convenient representation reduces the aforementioned transformations to simple arithmetic:


R += 1 (add an electron to the outer shell)
R += 33 (add an electron to the second outer shell)
R += 65 (add two electrons to the second outer shell; remove one from the first)
R += 1089 (add an electron to the third outer shell)
R += 2145 (add two electrons to the third outer shell; remove one from the second)
R *= 33, R += 1 (add a new shell containing a single electron)


All that's left is to somehow encode which transformation has to be applied to pass from a particular atom to the next. The differences of the integer representations of two consecutive atoms are as follows:

[1 1 65 1 1 1 1 1 1 1 2369 1 1 1 1 1 1 1 78401 1 33 33 33 65 1 33 33 33 65 1 1 1 1 1 1 1 2598017 1 33 33 65 33 1 65 33 65 1 1 1 1 1 1 1 1 85745345 1 33 1089 2145 1089 1089 1089 1089 33 2145 1089 1089 1089 1089 1089 33 33 33 33 33 33 33 65 33 1 1 1 1 1 1 1 2830095041 1 33 33 2145 1089 1089 2145 1089 33 2145 1089 1089 1089 1089 1089 65 1 33 33 33 33 33 33 65 1 1 1 1 1 1 1]


The unique differences in this array are the following:

[1 33 65 1089 2145 2369 78401 2598017 85745345 2830095041]


All but the first 5 correspond to instances when a new shell is added; these can be omitted since multiplying by 33 and adding 1 yields the same result as adding the difference.

Since we have to add a new shell if and only if the current atom has exactly eight electrons in its outer shell (with the exception of He (2) ↦ Li (3), which can be encoded as add 65), we can encode those transformations as add 1 and determine the need for multiplication on the fly.

Thus, if we define

X := 0
I := 0
L := [33 1089 65 2145 1]
T := [1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 3 1 0 0 0 3 1 1 1 1 1 1 1 1 1 0 0 3 0 1 3 0 3 1 1 1 1 1 1 1 1 1 1 0 2 4 2 2 2 2 0 4 2 2 2 2 2 0 0 0 0 0 0 0 3 0 1 1 1 1 1 1 1 1 1 0 0 4 2 2 4 2 0 4 2 2 2 2 2 3 1 0 0 0 0 0 0 3 1 1 1 1 1 1 1]


the electron configuration of the Nth atom can be computed as follows:

while(X &lt; N):
    R *= (33 ** (R % 33 == 8))
    R += L[T[X]]
    X += 1


How it works

" Push 0, the initial value of R; convert the following array into an integer by
  considering it a base 256 number, then back to the array of its digits in base 6.       ";

0"hTHøìð¼Ä¿håêÛ¾ªÔ¼"256b6b

" Replace each 5 in the resulting array by [4 4 4 4 4 4 4 4]. This yields the array T
  from the above section.                                                                 ";

5a/4a8**

" Read an integer N from STDIN and discard all but the first N elements of T.             ";

li&lt;

" For each element Y of the remainder of T, do the following:                             ";

{
    [33:B_B*65_B*1]=\   " Define B := 33, push L, retrieve L[Y] and swap it with R.       ";

    _B%8=B\#*           " Execute R *= 33 ** (R % 33 == 8).                               ";

    +                   " Execute R += L[Y].                                              ";
}/

" Convert R into the array of its digits in base 33, remove eventual zeros (Palladium)
  and replace the resulting array with its string representation.                         ";

Bb0-`


Example run

$ base64 -d &gt; electrons.cjam &lt;&lt;&lt; MCJoVEgM+OzwErzEGL9o5erbvqrUB4YZhrwRIjI1NmI2YjVhLzRhOCoqbGk8e1szMzpCX0IqNjVfQioxXT1cX0IlOD1CXCMqK30vQmIwLWA=
$ cksum electrons.cjam
3709391992 80 electrons.cjam
$ for i in {1..118}; do LANG=en_US cjam electrons.cjam &lt;&lt;&lt; $i; echo; done
[1]
[2]
[2 1]
[2 2]
[2 3]
[2 4]
[2 5]
[2 6]
[2 7]
[2 8]
[2 8 1]
[2 8 2]
[2 8 3]
[2 8 4]
[2 8 5]
[2 8 6]
[2 8 7]
[2 8 8]
[2 8 8 1]
[2 8 8 2]
[2 8 9 2]
[2 8 10 2]
[2 8 11 2]
[2 8 13 1]
[2 8 13 2]
[2 8 14 2]
[2 8 15 2]
[2 8 16 2]
[2 8 18 1]
[2 8 18 2]
[2 8 18 3]
[2 8 18 4]
[2 8 18 5]
[2 8 18 6]
[2 8 18 7]
[2 8 18 8]
[2 8 18 8 1]
[2 8 18 8 2]
[2 8 18 9 2]
[2 8 18 10 2]
[2 8 18 12 1]
[2 8 18 13 1]
[2 8 18 13 2]
[2 8 18 15 1]
[2 8 18 16 1]
[2 8 18 18]
[2 8 18 18 1]
[2 8 18 18 2]
[2 8 18 18 3]
[2 8 18 18 4]
[2 8 18 18 5]
[2 8 18 18 6]
[2 8 18 18 7]
[2 8 18 18 8]
[2 8 18 18 8 1]
[2 8 18 18 8 2]
[2 8 18 18 9 2]
[2 8 18 19 9 2]
[2 8 18 21 8 2]
[2 8 18 22 8 2]
[2 8 18 23 8 2]
[2 8 18 24 8 2]
[2 8 18 25 8 2]
[2 8 18 25 9 2]
[2 8 18 27 8 2]
[2 8 18 28 8 2]
[2 8 18 29 8 2]
[2 8 18 30 8 2]
[2 8 18 31 8 2]
[2 8 18 32 8 2]
[2 8 18 32 9 2]
[2 8 18 32 10 2]
[2 8 18 32 11 2]
[2 8 18 32 12 2]
[2 8 18 32 13 2]
[2 8 18 32 14 2]
[2 8 18 32 15 2]
[2 8 18 32 17 1]
[2 8 18 32 18 1]
[2 8 18 32 18 2]
[2 8 18 32 18 3]
[2 8 18 32 18 4]
[2 8 18 32 18 5]
[2 8 18 32 18 6]
[2 8 18 32 18 7]
[2 8 18 32 18 8]
[2 8 18 32 18 8 1]
[2 8 18 32 18 8 2]
[2 8 18 32 18 9 2]
[2 8 18 32 18 10 2]
[2 8 18 32 20 9 2]
[2 8 18 32 21 9 2]
[2 8 18 32 22 9 2]
[2 8 18 32 24 8 2]
[2 8 18 32 25 8 2]
[2 8 18 32 25 9 2]
[2 8 18 32 27 8 2]
[2 8 18 32 28 8 2]
[2 8 18 32 29 8 2]
[2 8 18 32 30 8 2]
[2 8 18 32 31 8 2]
[2 8 18 32 32 8 2]
[2 8 18 32 32 10 1]
[2 8 18 32 32 10 2]
[2 8 18 32 32 11 2]
[2 8 18 32 32 12 2]
[2 8 18 32 32 13 2]
[2 8 18 32 32 14 2]
[2 8 18 32 32 15 2]
[2 8 18 32 32 16 2]
[2 8 18 32 32 18 1]
[2 8 18 32 32 18 2]
[2 8 18 32 32 18 3]
[2 8 18 32 32 18 4]
[2 8 18 32 32 18 5]
[2 8 18 32 32 18 6]
[2 8 18 32 32 18 7]
[2 8 18 32 32 18 8]