Periodic table: Difference between revisions

Content added Content deleted
(Added Go)
(→‎{{header|ALGOL 68}}: Tweak and use the same test cases as Wren, etc.)
Line 68: Line 68:
INT group multiplier = 100;
INT group multiplier = 100;
[ 1 : max atomic number ]INT position;
[ 1 : max atomic number ]INT position;
# construct the positions of the elements in the table #
STRING periodic table = "- ="
+ "-- -----="
+ "-- -----="
+ "-----------------="
+ "-----------------="
+ "--8--------------="
+ "--9--------------="
;
# construct the positions of the elements in the table #
# from the outline #
BEGIN
BEGIN
STRING periodic table = "- ="
+ "-- -----="
+ "-- -----="
+ "-----------------="
+ "-----------------="
+ "--8--------------="
+ "--9--------------="
;
INT period := 1;
INT period := 1;
INT group := 1;
INT group := 1;
Line 84: Line 83:
FOR t FROM LWB periodic table TO UPB periodic table DO
FOR t FROM LWB periodic table TO UPB periodic table DO
CHAR p = periodic table[ t ];
CHAR p = periodic table[ t ];
IF p = " " THEN
IF p = "8" OR p = "9" THEN
# no element at this position #
SKIP
ELIF p = "8" OR p = "9" THEN
# lantanoids or actinoids #
# lantanoids or actinoids #
INT series period = IF p = "8" THEN 8 ELSE 9 FI;
INT series period = IF p = "8" THEN 8 ELSE 9 FI;
Line 96: Line 92:
series group +:= 1
series group +:= 1
OD
OD
ELSE
ELIF p /= " " THEN
# there is a single element here #
# there is a single element here #
position[ element ] := ( group multiplier * group ) + period;
position[ element ] := ( group multiplier * group ) + period;
Line 110: Line 106:
END;
END;
# display the period and group numbers of test elements #
# display the period and group numbers of test elements #
[]INT test = ( 1, 2, 29, 42, 57, 58, 72, 89, 113 );
[]INT test = ( 1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113 );
FOR t FROM LWB test TO UPB test DO
FOR t FROM LWB test TO UPB test DO
INT e = test[ t ];
INT e = test[ t ];
Line 134: Line 130:
Element 57 -> 8, 4
Element 57 -> 8, 4
Element 58 -> 8, 5
Element 58 -> 8, 5
Element 59 -> 8, 6
Element 71 -> 8, 18
Element 72 -> 6, 4
Element 72 -> 6, 4
Element 89 -> 9, 4
Element 89 -> 9, 4
Element 90 -> 9, 5
Element 103 -> 9, 18
Element 113 -> 7, 13
Element 113 -> 7, 13
</pre>
</pre>