Periodic table: Difference between revisions

J
(J)
Line 411:
Atomic number 113 -> 7, 13
</pre>
 
=={{header|J}}==
 
Basically, here, we want a lookup table. For example:
 
<lang J>PT=: (' ',.~[;._2) {{)n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1 H He
2 Li Be B C N O F Ne
3 Na Mg Al Si P S Cl Ar
4 K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr
5 Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe
6 Cs Ba * Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn
7 Fr Ra - Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og
8 Lantanoidi* La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu
9 Aktinoidi- Ak Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr
}}
 
ptrc=: {{
tokens=. (#~ (3>#)@> * */@(tolower~:toupper)@>) ~.,;:,PT
ndx=. (>' ',L:0' ',L:0~tokens) {.@I.@E."1 ,PT
Lantanoidi=. ndx{+/\'*'=,PT
Aktinoidi=. ndx{+/\'-'=,PT
j=. 13|3*Lantanoidi+3*Aktinoidi
k=. {:$PT
0,}."1/:~j,.(<.ndx%k),.1+(/:~@~. i. ])k|ndx
}}
 
rowcol=: ptrc''</lang>
 
In other words, start with a hand crafted representation of the periodic table. Elements here are tokens with 1 or 2 letters. Locate the position of each token in the table. Get an initial row and column number from the character positions in the table. Translate character column to periodic table column by enumerating the unique (sorted) list of column numbers and using the index in that list. Character row was already periodic table row. Most elements here were already in atomic number order, and we can fix the exceptions by temporarily prefixing each row,col value and sorting. (Here, we use 0 for the first 56 elements, 3 for the next 17 elements (after Lantanoidi, before Aktinoidi), 12 for the next 15 (after Aktinoidi), 2 for the next 15 (the Lantanoidi) and 11 for the final 15 elements (the Aktinoidi).)
 
Thus:
 
<lang J> 1 2 29 42 57 58 72 89 { rowcol
1 1
1 18
4 11
5 6
8 4
8 5
6 4
9 4</lang>
 
 
=={{header|Julia}}==
6,962

edits