Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Periodic_table

View file

@ -0,0 +1,58 @@
;Task:
Display the row and column in the periodic table of the given atomic number.
;The periodic table:
Let us consider the following periodic table representation.
<pre>
__________________________________________________________________________
| 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 |
|__________________________________________________________________________|
</pre>
;Example test cases;
* &nbsp; <code>1</code> -> <code>1 1</code>
* &nbsp; <code>2</code> -> <code>1 18</code>
* &nbsp; <code>29</code> -> <code>4 11</code>
* &nbsp; <code>42</code> -> <code>5 6</code>
* &nbsp; <code>57</code> -> <code>8 4</code>
* &nbsp; <code>58</code> -> <code>8 5</code>
* &nbsp; <code>72</code> -> <code>6 4</code>
* &nbsp; <code>89</code> -> <code>9 4</code>
;Details;
The representation of the periodic table may be represented in various way. The one presented in this challenge does have the following property : Lantanides and Aktinoides are all in a dedicated row, hence there is no element that is placed at 6, 3 nor 7, 3.
You may take a look at the atomic number repartitions [https://en.wikipedia.org/wiki/Periodic_table#/media/File:Simple_Periodic_Table_Chart-blocks.svg here].
The atomic number is at least 1, at most 118.
;See also:
* &nbsp; [https://en.wikipedia.org/wiki/Periodic_table the periodic table]
* &nbsp; [https://twitter.com/CompSciFact/status/1537447575573233666 This task was an idea from CompSciFact]
* &nbsp; [https://ascii.periodni.com/index.html The periodic table in ascii] that was used as template
<br><br>

View file

@ -0,0 +1,44 @@
F perta(atomic)
-V
NOBLES = [2, 10, 18, 36, 54, 86, 118]
INTERTWINED = [0, 0, 0, 0, 0, 57, 89]
INTERTWINING_SIZE = 14
LINE_WIDTH = 18
V prev_noble = 0
V row = 0
Int col
L(noble) NOBLES
row = L.index
I atomic <= noble
V nb_elem = noble - prev_noble
V rank = atomic - prev_noble
I INTERTWINED[row] & atomic C INTERTWINED[row] .. INTERTWINED[row] + INTERTWINING_SIZE
row += 2
col = rank + 1
E
V nb_empty = LINE_WIDTH - nb_elem
V inside_left_element_rank = I noble > 2 {2} E 1
col = rank + (I rank > inside_left_element_rank {nb_empty} E 0)
L.break
prev_noble = noble
R (row + 1, col)
V TESTS = [
(1, (1, 1)),
(2, (1, 18)),
(29, (4,11)),
(42, (5, 6)),
(58, (8, 5)),
(59, (8, 6)),
(57, (8, 4)),
(71, (8, 18)),
(72, (6, 4)),
(89, (9, 4)),
(90, (9, 5)),
(103, (9, 18)),
]
L(input, out) TESTS
V found = perta(input)
print(TEST:#3 -> .format(input)String(found)(I found != out { ; ERROR: expected out} E ))

View file

@ -0,0 +1,11 @@
Lookup: ;INPUT: X = atomic number of the element of interest.
LDA PeriodicTable_Column,x
STA $20 ;store column number in memory (I chose $20 arbitrarily, you can store it anywhere)
LDA PeriodicTable_Row,x
STA $21 ;store row number in memory
RTS
PeriodicTable_Column:
db $ff,$01,$18,$01,$02,$13,$14,$15,$16,$17,$18,... ;I don't need to write them all out, the concept is self-explanatory enough.
PeriodicTable_Row:
db $ff,$01,$01,$02,$02,$02,$02,$02,$02,$02,$02,...

View file

@ -0,0 +1,20 @@
Lookup:
;input: D0.W = the atomic number of interest.
LEA PeriodicTable,A0
ADD.W D0,D0 ;we're indexing a table of words, so double the index.
MOVE.W (A0,D0),D0 ;D0.W contains row number in the high byte and column number in the low byte.
RTS
PeriodicTable:
DC.W $FFFF ;padding since arrays start at zero in assembly.
DC.W $0101 ;HYDROGEN
DC.W $0118 ;HELIUM
DC.W $0201 ;LITHIUM
DC.W $0202 ;BERYLLIUM
DC.W $0213 ;BORON
DC.W $0214 ;CARBON
DC.W $0215 ;NITROGEN
DC.W $0216 ;OXYGEN
DC.W $0217 ;FLUORINE
DC.W $0218 ;NEON
;etc.

View file

@ -0,0 +1,61 @@
BEGIN # display the period and group number of an element, #
# given its atomic number #
INT max atomic number = 118; # highest known element #
# the positions are stored as: #
# ( group number * group multiplier ) + period #
INT group multiplier = 100;
[ 1 : max atomic number ]INT position;
# construct the positions of the elements in the table #
BEGIN
STRING periodic table = "- ="
+ "-- -----="
+ "-- -----="
+ "-----------------="
+ "-----------------="
+ "--8--------------="
+ "--9--------------="
;
INT period := 1;
INT group := 1;
INT element := 1;
FOR t FROM LWB periodic table TO UPB periodic table DO
CHAR p = periodic table[ t ];
IF p = "8" OR p = "9" THEN
# lantanoids or actinoids #
INT series period = IF p = "8" THEN 8 ELSE 9 FI;
INT series group := 4;
FOR e TO 15 DO
position[ element ] := ( group multiplier * series group ) + series period;
element +:= 1;
series group +:= 1
OD
ELIF p /= " " THEN
# there is a single element here #
position[ element ] := ( group multiplier * group ) + period;
element +:= 1;
IF p = "=" THEN
# final element of the period #
period +:= 1;
group := 0
FI
FI;
group +:= 1
OD
END;
# display the period and group numbers of test elements #
[]INT test = ( 1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113 );
FOR t FROM LWB test TO UPB test DO
INT e = test[ t ];
IF e < LWB position OR e > UPB position THEN
print( ( "Invalid element: ", whole( e, 0 ), newline ) )
ELSE
INT period = position[ e ] MOD group multiplier;
INT group = position[ e ] OVER group multiplier;
print( ( "Element ", whole( e, -3 )
, " -> ", whole( period, 0 ), ", ", whole( group, -2 )
, newline
)
)
FI
OD
END

View file

@ -0,0 +1,40 @@
REM Periodic table
DIM A(7)
DIM B(7)
REM Arrays A, B.
DATA 1, 2, 5, 13, 57, 72, 89, 104
DATA -1, 15, 25, 35, 72, 21, 58, 7
REM Example elements (atomic numbers).
DATA 1, 2, 29, 42, 57, 58, 72, 89, 90, 103
GOSUB SetAB:
FOR J = 0 TO 9
READ AtomicNum
GOSUB ShowRowAndColumn:
NEXT J
END
SetAB:
FOR I = 0 TO 7
READ A(I)
NEXT I
FOR I = 0 TO 7
READ B(I)
NEXT I
RETURN
ShowRowAndColumn:
I = 7
WHILE A(I) > AtomicNum
I = I - 1
WEND
M = AtomicNum + B(I)
R = M / 18
R = R + 1
C = M MOD 18
C = C + 1
PRINT AtomicNum;
PRINT " ->";
PRINT R;
PRINT C
RETURN

View file

@ -0,0 +1,8 @@
0 GR:HOME:COLOR=11:FORR=1TO7:FORC=1TO2:GOSUB7:NEXTC,R:COLOR=7:FORR=4TO7:FORC=3+(R>5)TO12:GOSUB7:NEXTC,R:COLOR=13:FORR=2TO7:FORC=13TO18:GOSUB7:NEXTC,R
1 forr=2to7:forc=13to18:GOSUB7:NEXTC,R:COLOR=14:R=8:FORC=4TO18:GOSUB7:NEXTC:COLOR=12:R=9:FORC=4TO18:GOSUB7:NEXTC:R=9:FORC=4TO18:GOSUB7:NEXTC:Z=2:R=7:C=3:GOSUB7:COLOR=14:R=6:C=3:GOSUB7:COLOR=15
2 S=14:W=18:FORI=1TO7:READN(I),I(I):NEXT:DATA2,0,10,0,18,0,36,0,54,0,86,57,118,89,1,1,1,2,1,18,29,4,11,42,5,6,57,8,4,58,8,5,72,6,4,89,9,4,59,8,6,71,8,18,90,9,5,103,9,18
3 FORT=1TO8:READA,Y,X:GOSUB4:PRINTRIGHT$(" "+STR$(A),3)"->"R" "LEFT$(STR$(C)+" ",3);:GOSUB7:NEXTT:VTAB23:END
4 N=0:FORR=1TO7:P=N:N=N(R):IFA>NTHEN:NEXTR
5 E=N-P:K=A-P:IFI(R)AND(I(R)<=AANDA<=I(R)+S)THENR=R+2:C=K+1:RETURN
6 E=W-E:L=1+(N>2):C=K+E*(K>L):RETURN
7 K=C+(R=1ANDC=2)*16:VLINR*4+Z,R*4+2ATK*2+1:RETURN

View file

@ -0,0 +1,17 @@
subroutine MostarPos(N)
dim A = { 1, 2, 5, 13, 57, 72, 89, 104}
dim B = {-1, 15, 25, 35, 72, 21, 58, 7}
I = 7
while A[I] > N
I -= 1
end while
M = N + B[I]
R = (M \ 18) +1
C = (M % 18) +1
print "Atomic number "; rjust(N,3); "-> "; R ; ", "; C
end subroutine
dim Element = {1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113}
for I = 0 to Element[?]-1
call MostarPos(Element[I])
next I

View file

@ -0,0 +1,201 @@
#include <gadget/gadget.h>
LIB_GADGET_START
/* prototypes */
GD_VIDEO put_chemical_cell( GD_VIDEO table, MT_CELL * E, DS_ARRAY E_data );
MT_CELL* load_chem_elements( MT_CELL * E, DS_ARRAY * E_data );
int select_box_chemical_elem( RDS(MT_CELL, Elements) );
void put_information(RDS( MT_CELL, elem), int i);
Main
GD_VIDEO table;
/* las dimensiones del terminal son muy importantes
para desplegar la tabla */
Resize_terminal(42,135);
Init_video( &table );
Gpm_Connect conn;
if ( ! Init_mouse(&conn)){
Msg_red("No se puede conectar al servidor del ratón\n");
Stop(1);
}
Enable_raw_mode();
Hide_cursor;
/* I declare a multitype array "Elements", and load the file that will populate this array. */
New multitype Elements;
Elements = load_chem_elements( pSDS(Elements) );
Throw( load_fail );
/* I create a "Button" object with which the execution will end. */
New objects Btn_exit;
Btn_exit = New_object_mouse( SMD(&Btn_exit), BUTTOM, " Terminar ", 6,44, 15, 0);
/* Fill the space on the screen with the table of chemical elements. */
table = put_chemical_cell( table, SDS(Elements) );
/* I print the screen and place the mouse object. */
Refresh(table);
Put object Btn_exit;
/* I wait for a mouse event. */
int c;
Waiting_some_clic(c)
{
if( select_box_chemical_elem(SDS(Elements)) ){
Waiting_some_clic(c) break;
}
if (Object_mouse( Btn_exit)) break;
Refresh(table);
Put object Btn_exit;
}
Free object Btn_exit;
Free multitype Elements;
Exception( load_fail ){
Msg_red("No es un archivo matriciable");
}
Free video table;
Disable_raw_mode();
Close_mouse();
Show_cursor;
At SIZE_TERM_ROWS,0;
Prnl;
End
void put_information(RDS(MT_CELL, elem), int i)
{
At 2,19;
Box_solid(11,64,67,17);
Color(15,17);
At 4,22; Print "Elemento (%s) = %s", (char*)$s-elem[i,5],(char*)$s-elem[i,6];
if (Cell_type(elem,i,7) == double_TYPE ){
At 5,22; Print "Peso atómico = %f", $d-elem[i,7];
}else{
At 5,22; Print "Peso atómico = (%ld)", $l-elem[i,7];
}
At 6,22; Print "Posición = (%ld, %ld)",$l-elem[i,0]+ ($l-elem[i,0]>=8 ? 0:1),$l-elem[i,1]+1;
At 8,22; Print "1ª energía de";
if (Cell_type(elem,i,12) == double_TYPE ){
At 9,22; Print "ionización (kJ/mol) = %.*f",2,$d-elem[i,12];
}else{
At 9,22; Print "ionización (kJ/mol) = ---";
}
if (Cell_type(elem,i,13) == double_TYPE ){
At 10,22; Print "Electronegatividad = %.*f",2,$d-elem[i,13];
}else{
At 10,22; Print "Electronegatividad = ---";
}
At 4,56; Print "Conf. electrónica:";
At 5,56; Print " %s", (char*)$s-elem[i,14];
At 7,56; Print "Estados de oxidación:";
if ( Cell_type(elem,i,15) == string_TYPE ){
At 8,56; Print " %s", (char*)$s-elem[i,15];
}else{
/* Strangely, when the file loader detects a "+n", it treats it as a string,
but when it detects a "-n", it treats it as a "long".
I must review that. */
At 8,56; Print " %ld", $l-elem[i,15];
}
At 10,56; Print "Número Atómico: %ld",$l-elem[i,4];
Reset_color;
}
int select_box_chemical_elem( RDS(MT_CELL, elem) )
{
int i;
Iterator up i [0:1:Rows(elem)]{
if ( Is_range_box( $l-elem[i,8], $l-elem[i,9], $l-elem[i,10], $l-elem[i,11]) ){
Gotoxy( $l-elem[i,8], $l-elem[i,9] );
Color_fore( 15 ); Color_back( 0 );
Box( 4,5, DOUB_ALL );
Gotoxy( $l-elem[i,8]+1, $l-elem[i,9]+2); Print "%ld",$l-elem[i,4];
Gotoxy( $l-elem[i,8]+2, $l-elem[i,9]+2); Print "%s",(char*)$s-elem[i,5];
Flush_out;
Reset_color;
put_information(SDS(elem),i);
return 1;
}
}
return 0;
}
GD_VIDEO put_chemical_cell(GD_VIDEO table, MT_CELL * elem, DS_ARRAY elem_data)
{
int i;
/* put each cell */
Iterator up i [0:1:Rows(elem)]{
long rx = 2+($l-elem[i,0]*4);
long cx = 3+($l-elem[i,1]*7);
long offr = rx+3;
long offc = cx+6;
Gotoxy(table, rx, cx);
Color_fore(table, $l-elem[i,2]);
Color_back(table,$l-elem[i,3]);
Box(table, 4,5, SING_ALL );
char Atnum[50], Elem[50];
sprintf(Atnum,"\x1b[3m%ld\x1b[23m",$l-elem[i,4]);
sprintf(Elem, "\x1b[1m%s\x1b[22m",(char*)$s-elem[i,5]);
Outvid(table,rx+1, cx+2, Atnum);
Outvid(table,rx+2, cx+2, Elem);
Reset_text(table);
/* Update positions of each cell to be detected by the mouse. */
$l-elem[i,8] = rx;
$l-elem[i,9] = cx;
$l-elem[i,10] = offr;
$l-elem[i,11] = offc;
}
/* put rows and cols */
Iterator up i [ 1: 1: 19 ]{
Gotoxy(table, 31, 5+(i-1)*7);
char num[5]; sprintf( num, "%d",i );
Outvid(table, num );
}
Iterator up i [ 1: 1: 8 ]{
Gotoxy(table, 3+(i-1)*4, 130);
char num[5]; sprintf( num, "%d",i );
Outvid(table, num );
}
Outvid( table, 35,116, "8");
Outvid( table, 39,116, "9");
/* others */
Color_fore(table, 15);
Color_back(table, 0);
Outvid(table,35,2,"Lantánidos ->");
Outvid(table,39,2,"Actínidos ->");
Reset_text(table);
return table;
}
MT_CELL* load_chem_elements( MT_CELL * E, DS_ARRAY * E_data )
{
F_STAT dataFile = Stat_file("chem_table.txt");
if( dataFile.is_matrix ){
/*
Set the ranges to read from the file.
You can choose the portion of the file that you want to upload.
*/
Range ptr E [0:1:dataFile.total_lines-1, 0:1:dataFile.max_tokens_per_line-1];
E = Load_matrix_mt( SDS(E), "chem_table.txt", dataFile, DET_LONG);
}else{
Is_ok=0;
}
return E;
}

View file

@ -0,0 +1,28 @@
10 REM Periodic table
20 CLS
30 DIM a(7),b(7)
40 GOSUB 100
50 FOR j = 0 TO 9
60 READ anum : GOSUB 140
70 NEXT j
80 END
90 REM Set arrays A, B.
100 FOR i = 0 TO 7 : READ a(i) : NEXT i
110 FOR i = 0 TO 7 : READ b(i) : NEXT i
120 RETURN
130 REM Show row AND column FOR element
140 i = 7
150 WHILE a(i) > anum
160 i = i-1
170 WEND
180 m = anum+b(i)
190 r = INT(m/18)+1
200 c = m MOD 18+1
210 PRINT anum "-> " r c
220 RETURN
230 REM DATA
240 REM Arrays A, B.
250 DATA 1,2,5,13,57,72,89,104
260 DATA -1,15,25,35,72,21,58,7
270 REM Example elements (atomic numbers).
280 DATA 1,2,29,42,57,58,72,89,90,103

View file

@ -0,0 +1,52 @@
dim a[1, 2, 5, 13, 57, 72, 89, 104]
dim b[-1, 15, 25, 35, 72, 21, 58, 7]
title "Periodic Table Search"
resize 0, 0, 220, 140
center
formid 1
formtext "Search"
buttonform 55, 40, 100, 20
formid 2
formtext ""
staticform 1, 1, 220, 20
do
if forms = 1 then
gosub searchtable
endif
button k, 27
wait
loop k <> 1
end
sub searchtable
input "Atomic number", e
let i = 8
do
let i = i - 1
loop a[i] > e
let m = e + b[i]
let r = int(m / 18) + 1
let c = int(m % 18) + 1
formid 2
formtext "Period: ", r, comma, " Group: ", c
updateform
return

View file

@ -0,0 +1,56 @@
rem uses carry command to perform modulus
rem compiles with FTCBASIC to 545 bytes com file
define e = 0, i = 0, m = 0, r = 0, c = 0, q = 0
dim a[1, 2, 5, 13, 57, 72, 89, 104]
dim b[-1, 15, 25, 35, 72, 21, 58, 7]
do
cls
print "Periodic Table Lookup"
print "0 to continue or 1 to quit: " \
input q
if q = 0 then
gosub searchtable
endif
pause
loop q <> 1
end
sub searchtable
print "Atomic number: " \
input e
let i = 8
do
let i = i - 1
loop @a[i] > e
let m = e + @b[i]
let r = m / 18
carry c
let r = r + 1
let c = c + 1
print "Period: " \
print r \
print " Group: " \
print c \
return

View file

@ -0,0 +1,18 @@
Sub MostarPos(N As Integer)
Dim As Integer M, I, R, C
Dim As Integer A(0 To 7) = { 1, 2, 5, 13, 57, 72, 89, 104} 'magic numbers
Dim As Integer B(0 To 7) = {-1, 15, 25, 35, 72, 21, 58, 7}
I = 7
While A(I) > N
I -= 1
Wend
M = N + B(I)
R = (M \ 18) +1
C = (M Mod 18) +1
Print Using "Atomic number ### -> #_, ##"; N; R; C
End Sub
Dim As Integer Element(0 To 12) = {1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113}
For I As Integer = 0 To Ubound(Element)
MostarPos(Element(I))
Next I

View file

@ -0,0 +1,68 @@
_window = 1
void local fn BuildPeriodicTableArrays
CFArrayRef periodicArr = @[@"",¬
@"H", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"He",¬
@"Li", @"Be", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"B", @"C", @"N", @"O", @"F", @"Ne",¬
@"Na", @"Mg", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"Al", @"Si", @"P", @"S", @"Cl", @"Ar",¬
@"K", @"Ca", @"Sc", @"Ti", @"V", @"Cr", @"Mn", @"Fe", @"Co", @"Ni", @"Cu", @"Zn", @"Ga", @"Ge", @"As", @"Se", @"Br", @"Kr",¬
@"Rb", @"Sr", @"Y", @"Zr", @"Nb", @"Mo", @"Tc", @"Ru", @"Rh", @"Pd", @"Ag", @"Cd", @"In", @"Sn", @"Sb", @"Te", @"I", @"Xe",¬
@"Cs", @"Ba", @"Lu", @"Hf", @"Ta", @"W", @"Re", @"Os", @"Ir", @"Pt", @"Au", @"Hg", @"Tl", @"Pb", @"Bi", @"Po", @"At", @"Rn",¬
@"Fr", @"Ra", @"Lr", @"Rf", @"Db", @"Sg", @"Bh", @"Hs", @"Mt", @"Ds", @"Rg", @"Cn", @"Nh", @"Fl", @"Mc", @"Lv", @"Ts", @"Og",¬
@"", @"", @"La", @"Ce", @"Pr", @"Nd", @"Pm", @"Sm", @"Eu", @"Gd", @"Tb", @"Dy", @"Ho", @"Er", @"Tm", @"Yb", @"", @"",¬
@"", @"", @"Ac", @"Th", @"Pa", @"U", @"NP", @"Pu", @"Am", @"Cm", @"Bk", @"Cf", @"Es", @"Fm", @"Md", @"No", @"", @""]
AppSetProperty( @"periodicTable", periodicArr )
CFArrayRef numbersArr = @[@"",¬
@"1", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"2",¬
@"3", @"4", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"5", @"6", @"7", @"8", @"9", @"10",¬
@"11", @"12", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"13", @"14", @"15", @"16", @"17", @"18",¬
@"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29", @"30", @"31", @"32", @"33", @"34", @"35", @"36",¬
@"37", @"38", @"39", @"40", @"41", @"42", @"43", @"44", @"45", @"46", @"47", @"48", @"49", @"50", @"51", @"52", @"53", @"54",¬
@"55", @"56", @"71", @"72", @"73", @"74", @"75", @"76", @"77", @"78", @"79", @"80", @"81", @"82", @"83", @"84", @"85", @"86",¬
@"87", @"88", @"103", @"104", @"105", @"106", @"107", @"108", @"109", @"110", @"111", @"112", @"113", @"114", @"114", @"116", @"117", @"118",¬
@"", @"", @"57", @"58", @"59", @"60", @"61", @"62", @"63", @"64", @"65", @"66", @"67", @"68", @"59", @"70", @"", @"",¬
@"", @"", @"89", @"90", @"91", @"92", @"93", @"94", @"95", @"96", @"97", @"98", @"99", @"100", @"101", @"102", @"", @""]
AppSetProperty( @"periodicNumbers", numbersArr )
end fn
void local fn BuildWindow
NSInteger i, j, row
CGRect r
CFArrayRef periodicArr, numbersArr
CFStringRef tempStr
periodicArr = fn AppProperty( @"periodicTable" )
numbersArr = fn AppProperty( @"periodicNumbers" )
window _window, @"Periodic Table", ( 0, 0, 700, 400 )
WindowSetBackgroundColor( _window, fn ColorWhite )
j = 0 : row = 350
r = fn CGRectMake( 10, row, 36, 40 )
for i = 1 to 162
if fn StringIsEqual( periodicArr[i], @"" ) then tempStr = @"" else tempStr = fn StringWithFormat( @"%@\n%@", numbersArr[i], periodicArr[i] )
textfield i,, tempStr, r, _window
TextFieldSetBackgroundColor( i, fn ColorBlue )
TextFieldSetTextColor( i, fn ColorWhite )
ControlSetFontWithName( i, @"Menlo", 12.0 )
ControlSetAlignment(i, NSTextAlignmentCenter )
r = fn CGRectOffset( r, 38, 0 )
j++
if ( j == 18 )
row = row - 42
r = fn CGRectMake( 10, row, 36, 40 )
j = 0
end if
next
for i = 1 to 162
if fn StringIsEqual( fn ControlStringValue( i ), @"" ) then ViewRemoveFromSuperview( i )
next
end fn
fn BuildPeriodicTableArrays
fn BuildWindow
HandleEvents

View file

@ -0,0 +1,27 @@
10 REM Periodic table
20 DIM A(7), B(7)
30 GOSUB 200
40 FOR J% = 0 TO 9
50 READ ANUM%: GOSUB 400
60 NEXT J%
70 END
190 REM Set arrays A, B.
200 FOR I% = 0 TO 7: READ A(I%): NEXT I%
210 FOR I% = 0 TO 7: READ B(I%): NEXT I%
220 RETURN
390 REM Show row and column for element
400 I% = 7
410 WHILE A(I%) > ANUM%
420 I% = I% - 1
430 WEND
440 M% = ANUM% + B(I%)
450 R% = M% \ 18 + 1
460 C% = M% MOD 18 + 1
470 PRINT ANUM%;"->";R%;C%
480 RETURN
990 REM Data
1000 REM Arrays A, B.
1010 DATA 1, 2, 5, 13, 57, 72, 89, 104
1020 DATA -1, 15, 25, 35, 72, 21, 58, 7
1030 REM Example elements (atomic numbers).
1040 DATA 1, 2, 29, 42, 57, 58, 72, 89, 90, 103

View file

@ -0,0 +1,22 @@
Sub MostarPos(N As Integer) 'Mostrar fila y columna para el elemento
Dim M, I, R, C As Integer
Dim A As Integer[] = [1, 2, 5, 13, 57, 72, 89, 104] 'magic numbers
Dim B As Integer[] = [-1, 15, 25, 35, 72, 21, 58, 7]
I = 7
While A[I] > N
Dec I
Wend
M = N + B[I]
R = (M \ 18) + 1
C = (M Mod 18) + 1
Print "Atomic number "; Format(N, "###"); " -> "; R; ", "; C
End
Public Sub Main()
Dim Element As Integer[] = [1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113]
For e As Integer = 0 To 12
MostarPos(Element[e])
Next
End

View file

@ -0,0 +1,47 @@
package main
import (
"fmt"
"log"
)
var limits = [][2]int{
{3, 10}, {11, 18}, {19, 36}, {37, 54}, {55, 86}, {87, 118},
}
func periodicTable(n int) (int, int) {
if n < 1 || n > 118 {
log.Fatal("Atomic number is out of range.")
}
if n == 1 {
return 1, 1
}
if n == 2 {
return 1, 18
}
if n >= 57 && n <= 71 {
return 8, n - 53
}
if n >= 89 && n <= 103 {
return 9, n - 85
}
var row, start, end int
for i := 0; i < len(limits); i++ {
limit := limits[i]
if n >= limit[0] && n <= limit[1] {
row, start, end = i+2, limit[0], limit[1]
break
}
}
if n < start+2 || row == 4 || row == 5 {
return row, n - start + 1
}
return row, n - end + 18
}
func main() {
for _, n := range []int{1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113} {
row, col := periodicTable(n)
fmt.Printf("Atomic number %3d -> %d, %-2d\n", n, row, col)
}
}

View file

@ -0,0 +1,24 @@
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''

View file

@ -0,0 +1,9 @@
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

View file

@ -0,0 +1,28 @@
def limits: [[3,10], [11,18], [19,36], [37,54], [55,86], [87,118]];
def periodicTable(n):
if (n < 1 or n > 118) then "Atomic number is out of range." | error
elif n == 1 then [1, 1]
elif n == 2 then [1, 18]
elif (n >= 57 and n <= 71) then [8, n - 53]
elif (n >= 89 and n <= 103) then [9, n - 85]
else
first( range( 0; limits|length) as $i
| limits[$i] as $limit
| if (n >= $limit[0] and n <= $limit[1])
then {row: ($i + 2),
start: $limit[0],
end: $limit[1] }
else empty
end)
| if (n < .start + 2 or .row == 4 or .row == 5)
then [.row, n - .start + 1]
else [.row, n - .end + 18]
end
end;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
(1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113) as $n
| periodicTable($n) as [$r, $c]
| "Atomic number \($n|lpad(3)) -> \($r) \($c)"

View file

@ -0,0 +1,23 @@
const limits = [3:10, 11:18, 19:36, 37:54, 55:86, 87:118]
function periodic_table(n)
(n < 1 || n > 118) && error("Atomic number is out of range.")
n == 1 && return [1, 1]
n == 2 && return [1, 18]
57 <= n <= 71 && return [8, n - 53]
89 <= n <= 103 && return [9, n - 85]
row, limitstart, limitstop = 0, 0, 0
for i in eachindex(limits)
if limits[i].start <= n <= limits[i].stop
row, limitstart, limitstop = i + 1, limits[i].start, limits[i].stop
break
end
end
return (n < limitstart + 2 || row == 4 || row == 5) ?
[row, n - limitstart + 1] : [row, n - limitstop + 18]
end
for n in [1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113]
rc = periodic_table(n)
println("Atomic number ", lpad(n, 3), " -> ($(rc[1]), $(rc[2]))")
end

View file

@ -0,0 +1,15 @@
ClearAll[FindPeriodGroup]
FindPeriodGroup[n_Integer] := Which[57 <= n <= 70,
{8, n - 53}
,
89 <= n <= 102,
{9, n - 85}
,
1 <= n <= 118,
{ElementData[n, "Period"], ElementData[n, "Group"]}
,
True,
Missing["Element does not exist"]
]
Row[{"Element ", #, " -> ", FindPeriodGroup[#]}] & /@ {1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113} // Column
Graphics[Text[#, {1, -1} Reverse@FindPeriodGroup[#]] & /@ Range[118]]

View file

@ -0,0 +1,32 @@
10 REM Periodic table
20 GOSUB 200
30 FOR J = 0 TO 9
40 READ N
50 GOSUB 400
60 NEXT J
70 END
190 REM Set arrays A, B.
200 DIM A(7), B(7)
210 FOR I = 0 TO 7
220 READ A(I)
230 NEXT I
240 FOR I = 0 TO 7
250 READ B(I)
260 NEXT I
270 RETURN
390 REM Show row and column for element
400 LET I = 7
410 IF A(I) <= N THEN 440
420 LET I = I-1
430 GOTO 410
440 LET M = N+B(I)
450 LET R = INT(M/18)+1
460 LET C = M-INT(M/18)*18+1
470 PRINT N; "->"; R; C
480 RETURN
990 REM Data.
1000 REM Arrays A, B.
1010 DATA 1, 2, 5, 13, 57, 72, 89, 104
1020 DATA -1, 15, 25, 35, 72, 21, 58, 7
1030 REM Example elements (atomic numbers).
1040 DATA 1, 2, 29, 42, 57, 58, 72, 89, 90, 103

View file

@ -0,0 +1,23 @@
10 REM Periodic table
20 GOSUB 200
30 FOR J=0 TO 9:READ ANUM:GOSUB 400:NEXT J
40 END
190 REM ** Set arrays A, B.
200 DIM A(7),B(7)
210 FOR I=0 TO 7:READ A(I):NEXT I
220 FOR I=0 TO 7:READ B(I):NEXT I
230 RETURN
390 REM ** Show row and column for element
400 I=7
410 IF A(I)>ANUM THEN I=I-1:GOTO 410
420 M=ANUM+B(I)
430 R=INT(M/18)+1
440 C=M-INT(M/18)*18+1
450 PRINT ANUM;"->";R;C
460 RETURN
990 REM ** Data.
1000 REM ** Arrays A, B.
1010 DATA 1,2,5,13,57,72,89,104
1020 DATA -1,15,25,35,72,21,58,7
1030 REM ** Example elements (atomic numbers).
1040 DATA 1,2,29,42,57,58,72,89,90,103

View file

@ -0,0 +1,24 @@
import std/strformat
const Limits = [3..10, 11..18, 19..36, 37..54, 55..86, 87..118]
func periodicTable(n: Positive): (int, int) =
doAssert n in 1..118, "Atomic number is out of range."
if n == 1: return (1, 1)
if n == 2: return (1, 18)
if n in 57..71: return (8, n - 53)
if n in 89..103: return (9, n - 85)
var row, start, stop = 0
for i, limit in Limits:
if n in limit:
row = i + 2
start = limit.a
stop = limit.b
break
if n < start + 2 or row == 4 or row == 5:
return (row, n - start + 1)
result = (row, n - stop + 18)
for n in [1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113]:
let (row, col) = periodicTable(n)
echo &"Atomic number {n:3} → {row}, {col}"

View file

@ -0,0 +1,26 @@
<?php
// Periodic table
class PeriodicTable
{
private $aArray = array(1, 2, 5, 13, 57, 72, 89, 104);
private $bArray = array(-1, 15, 25, 35, 72, 21, 58, 7);
public function rowAndColumn($n)
{
$i = 7;
while ($this->aArray[$i] > $n)
$i--;
$m = $n + $this->bArray[$i];
return array(floor($m / 18) + 1, $m % 18 + 1);
}
}
$pt = new PeriodicTable();
// Example elements (atomic numbers).
foreach ([1, 2, 29, 42, 57, 58, 72, 89, 90, 103] as $n) {
list($r, $c) = $pt->rowAndColumn($n);
echo $n, " -> ", $r, " ", $c, PHP_EOL;
}
?>

View file

@ -0,0 +1,15 @@
use strict;
use warnings; no warnings 'uninitialized';
use feature 'say';
use List::Util <sum head>;
sub divmod { int $_[0]/$_[1], $_[0]%$_[1] }
my $b = 18;
my(@offset,@span,$cnt);
push @span, ($cnt++) x $_ for <1 3 8 44 15 17 15 15>;
@offset = (16, 10, 10, (2*$b)+1, (-2*$b)-15, (2*$b)+1, (-2*$b)-15);
for my $n (<1 2 29 42 57 58 72 89 90 103 118>) {
printf "%3d: %2d, %2d\n", $n, map { $_+1 } divmod $n-1 + sum(head $span[$n-1], @offset), $b;
}

View file

@ -0,0 +1,34 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">match_wp</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">prc</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #000000;">18</span><span style="color: #0000FF;">,</span><span style="color: #000000;">36</span><span style="color: #0000FF;">,</span><span style="color: #000000;">54</span><span style="color: #0000FF;">,</span><span style="color: #000000;">86</span><span style="color: #0000FF;">,</span><span style="color: #000000;">118</span><span style="color: #0000FF;">,</span><span style="color: #000000;">119</span><span style="color: #0000FF;">}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">row</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">abs</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">binary_search</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">))-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">col</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">row</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">col</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span><span style="color: #0000FF;">+(</span><span style="color: #000000;">row</span><span style="color: #0000FF;">></span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">col</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">18</span><span style="color: #0000FF;">-(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">row</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]-</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">match_wp</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">col</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">2</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">row</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">col</span><span style="color: #0000FF;">+</span><span style="color: #000000;">14</span><span style="color: #0000FF;">}</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">else</span> <span style="color: #000080;font-style:italic;">-- matches above ascii:</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">col</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">2</span><span style="color: #0000FF;">+(</span><span style="color: #000000;">row</span><span style="color: #0000FF;">></span><span style="color: #000000;">5</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">row</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">col</span><span style="color: #0000FF;">+</span><span style="color: #000000;">15</span><span style="color: #0000FF;">}</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">row</span><span style="color: #0000FF;">,</span><span style="color: #000000;">col</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">pt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">19</span><span style="color: #0000FF;">),</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..$]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">18</span><span style="color: #0000FF;">)})</span> <span style="color: #000080;font-style:italic;">-- column headings</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">9</span> <span style="color: #008080;">do</span> <span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span> <span style="color: #000080;font-style:italic;">-- row numbers</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">118</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">prc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">r</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">c</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">match_wp</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- (ascii only:)</span>
<span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">7</span><span style="color: #0000FF;">][</span><span style="color: #000000;">4</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">" L*"</span>
<span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">8</span><span style="color: #0000FF;">][</span><span style="color: #000000;">4</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">" A*"</span>
<span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">9</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..</span><span style="color: #000000;">4</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Lanthanide:"</span><span style="color: #0000FF;">}</span>
<span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">10</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">..</span><span style="color: #000000;">4</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">" Actinide:"</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">pt</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"|"</span><span style="color: #0000FF;">}}),</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)})</span>
<!--

View file

@ -0,0 +1,54 @@
(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">ptxt</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
__________________________________________________________________________
| 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 |
|__________________________________________________________________________|
"""</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">tablify</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">ptxt</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">lines</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ptxt</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">l</span> <span style="color: #008080;">in</span> <span style="color: #000000;">lines</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ln</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]-</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ln</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">ln</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">9</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,{})</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">5</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">by</span> <span style="color: #000000;">4</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">c</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]>=</span><span style="color: #008000;">'A'</span> <span style="color: #008080;">and</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]<=</span><span style="color: #008000;">' '</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[$]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[$],{</span><span style="color: #7060A8;">trim</span><span style="color: #0000FF;">(</span><span style="color: #000000;">l</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">..</span><span style="color: #000000;">j</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]),</span><span style="color: #000000;">ln</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">7</span><span style="color: #0000FF;">][</span><span style="color: #000000;">3</span><span style="color: #0000FF;">..</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">9</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">6</span><span style="color: #0000FF;">][</span><span style="color: #000000;">3</span><span style="color: #0000FF;">..</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">8</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">7</span><span style="color: #0000FF;">],{},{})</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">pt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"(%s) is at %d, %d"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">tablify</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ptxt</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">e</span> <span style="color: #008080;">in</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">29</span><span style="color: #0000FF;">,</span><span style="color: #000000;">42</span><span style="color: #0000FF;">,</span><span style="color: #000000;">57</span><span style="color: #0000FF;">,</span><span style="color: #000000;">58</span><span style="color: #0000FF;">,</span><span style="color: #000000;">59</span><span style="color: #0000FF;">,</span><span style="color: #000000;">71</span><span style="color: #0000FF;">,</span><span style="color: #000000;">72</span><span style="color: #0000FF;">,</span><span style="color: #000000;">89</span><span style="color: #0000FF;">,</span><span style="color: #000000;">90</span><span style="color: #0000FF;">,</span><span style="color: #000000;">103</span><span style="color: #0000FF;">,</span><span style="color: #000000;">113</span><span style="color: #0000FF;">}</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Element %d %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">e</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pt</span><span style="color: #0000FF;">[</span><span style="color: #000000;">e</span><span style="color: #0000FF;">]})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--

View file

@ -0,0 +1,46 @@
def perta(atomic) -> (int, int):
NOBLES = 2, 10, 18, 36, 54, 86, 118
INTERTWINED = 0, 0, 0, 0, 0, 57, 89
INTERTWINING_SIZE = 14
LINE_WIDTH = 18
prev_noble = 0
for row, noble in enumerate(NOBLES):
if atomic <= noble: # we are at the good row. We now need to determine the column
nb_elem = noble - prev_noble # number of elements on that row
rank = atomic - prev_noble # rank of the input element among elements
if INTERTWINED[row] and INTERTWINED[row] <= atomic <= INTERTWINED[row] + INTERTWINING_SIZE: # lantanides or actinides
row += 2
col = rank + 1
else: # not a lantanide nor actinide
# handle empty spaces between 1-2, 4-5 and 12-13.
nb_empty = LINE_WIDTH - nb_elem # spaces count as columns
inside_left_element_rank = 2 if noble > 2 else 1
col = rank + (nb_empty if rank > inside_left_element_rank else 0)
break
prev_noble = noble
return row+1, col
# small test suite
TESTS = {
1: (1, 1),
2: (1, 18),
29: (4,11),
42: (5, 6),
58: (8, 5),
59: (8, 6),
57: (8, 4),
71: (8, 18),
72: (6, 4),
89: (9, 4),
90: (9, 5),
103: (9, 18),
}
for input, out in TESTS.items():
found = perta(input)
print('TEST:{:3d} -> '.format(input) + str(found) + (f' ; ERROR: expected {out}' if found != out else ''))

View file

@ -0,0 +1,32 @@
SUB MostarPos (N)
DIM a(7)
RESTORE a:
FOR x = 0 TO 7: READ a(x): NEXT x
DIM b(7)
RESTORE b:
FOR x = 0 TO 7: READ b(x): NEXT x
I = 7
WHILE a(I) > N
I = I - 1
WEND
M = N + b(I)
R = (M \ 18) + 1
C = (M MOD 18) + 1
PRINT USING "Atomic number ### -> #_, ##"; N; R; C
END SUB
DIM Element(0 TO 12)
RESTORE elements
elements:
DATA 1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113
FOR x = 0 TO 12: READ Element(x): NEXT x
FOR I = 0 TO UBOUND(Element)
MostarPos (Element(I))
NEXT I
a:
DATA 1, 2, 5, 13, 57, 72, 89, 104
b:
DATA -1, 15, 25, 35, 72, 21, 58, 7

View file

@ -0,0 +1,7 @@
my $b = 18;
my @offset = 16, 10, 10, (2×$b)+1, (-2×$b)-15, (2×$b)+1, (-2×$b)-15;
my @span = flat ^8 Zxx <1 3 8 44 15 17 15 15>;
for <1 2 29 42 57 58 72 89 90 103> -> $n {
printf "%3d: %2d, %2d\n", $n, map {$_+1}, ($n-1 + [+] @offset.head(@span[$n-1])).polymod($b).reverse;
}

View file

@ -0,0 +1,47 @@
dim Element(12)
Element(0) = 1
Element(1) = 2
Element(2) = 29
Element(3) = 42
Element(4) = 57
Element(5) = 58
Element(6) = 59
Element(7) = 71
Element(8) = 72
Element(9) = 89
Element(10) = 90
Element(11) = 103
Element(12) = 113
for e = 0 to 12
call MostarPos Element(e)
next e
sub MostarPos N
dim A(7)
A(0) = 1
A(1) = 2
A(2) = 5
A(3) = 13
A(4) = 57
A(5) = 72
A(6) = 89
A(7) = 104
dim B(7)
B(0) = -1
B(1) = 15
B(2) = 25
B(3) = 35
B(4) = 72
B(5) = 21
B(6) = 58
B(7) = 7
I = 7
while A(I) > N
I = I - 1
wend
M = N + B(I)
R = int(M / 18) +1
C = (M mod 18) +1
print "Atomic number "; using("###", N); " -> "; R; ", "; C
end sub

View file

@ -0,0 +1,39 @@
(define (position-increment n)
(cond
((= n 1) '( 0 . 17))
((= n 2) '( 1 . -17))
((= n 4) '( 0 . 11))
((= n 10) '( 1 . -17))
((= n 12) '( 0 . 11))
((= n 18) '( 1 . -17))
((= n 36) '( 1 . -17))
((= n 54) '( 1 . -17))
((= n 56) '( 2 . 2))
((= n 71) '(-2 . -14))
((= n 86) '( 1 . -17))
((= n 88) '( 2 . 2))
((= n 103) '(-2 . -14))
(else '( 0 . 1))))
(define (move p i)
(cons (+ (car p) (car i))
(+ (cdr p) (cdr i))))
(define (position n)
(if (= n 1)
'(1 . 1)
(let ((m (- n 1)))
(move (position m)
(position-increment m)))))
(define (format-line n p)
(display n)
(display " -> ")
(display (car p))
(display " ")
(display (cdr p))
(newline))
(for-each (lambda (n)
(format-line n (position n)))
(list 1 2 29 42 57 58 72 89))

View file

@ -0,0 +1,9 @@
(define position*
(let ((memo (make-vector 118 #f)))
(lambda (n)
(let* ((mi (- n 1))
(mp (vector-ref memo mi)))
(or mp
(let ((p (position n)))
(vector-set! memo mi p)
p))))))

View file

@ -0,0 +1,48 @@
SUB MostarPos (n)
DIM a(0 TO 7)
LET a(0) = 1
LET a(1) = 2
LET a(2) = 5
LET a(3) = 13
LET a(4) = 57
LET a(5) = 72
LET a(6) = 89
LET a(7) = 104
DIM b(0 TO 7)
LET b(0) = -1
LET b(1) = 15
LET b(2) = 25
LET b(3) = 35
LET b(4) = 72
LET b(5) = 21
LET b(6) = 58
LET b(7) = 7
LET i = 7
DO WHILE a(i) > n
LET i = i - 1
LOOP
LET m = n + b(i)
LET r = IP(m / 18) + 1
LET c = REMAINDER(m, 18) + 1
PRINT USING "Atomic number ###": n;
PRINT " ->"; r; c
END SUB
DIM element(0 TO 12)
LET element(0) = 1
LET element(1) = 2
LET element(2) = 29
LET element(3) = 42
LET element(4) = 57
LET element(5) = 58
LET element(6) = 59
LET element(7) = 71
LET element(8) = 72
LET element(9) = 89
LET element(10) = 90
LET element(11) = 103
LET element(12) = 113
FOR e = 0 TO UBOUND(element)
CALL MostarPos (element(e))
NEXT e
END

View file

@ -0,0 +1,30 @@
import log
const limits = [[3, 10], [11, 18], [19, 36], [37, 54], [55, 86], [87, 118]]
fn main() {
for n in [1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113] {
row, col := periodic_table(n)
println("Atomic number ${n} -> ${row}, ${col}")
}
}
fn periodic_table(n int) (int, int) {
mut logged := log.Log{}
mut limit := []int{}
mut row, mut start, mut end := 0, 0, 0
if n < 1 || n > 118 {logged.fatal("Atomic number is out of range.")}
if n == 1 {return 1, 1}
if n == 2 {return 1, 18}
if n >= 57 && n <= 71 {return 8, n - 53}
if n >= 89 && n <= 103 {return 9, n - 85}
for i := 0; i < limits.len; i++ {
limit = limits[i]
if n >= limit[0] && n <= limit[1] {
row, start, end = i + 2, limit[0], limit[1]
break
}
}
if n < start + 2 || row == 4 || row == 5 {return row, n - start + 1}
return row, n - end + 18
}

View file

@ -0,0 +1,30 @@
import "./fmt" for Fmt
var limits = [3..10, 11..18, 19..36, 37..54, 55..86, 87..118]
var periodicTable = Fn.new { |n|
if (n < 1 || n > 118) Fiber.abort("Atomic number is out of range.")
if (n == 1) return [1, 1]
if (n == 2) return [1, 18]
if (n >= 57 && n <= 71) return [8, n - 53]
if (n >= 89 && n <= 103) return [9, n - 85]
var row
var start
var end
for (i in 0...limits.count) {
var limit = limits[i]
if (n >= limit.from && n <= limit.to) {
row = i + 2
start = limit.from
end = limit.to
break
}
}
if (n < start + 2 || row == 4 || row == 5) return [row, n - start + 1]
return [row, n - end + 18]
}
for (n in [1, 2, 29, 42, 57, 58, 59, 71, 72, 89, 90, 103, 113]) {
var rc = periodicTable.call(n)
Fmt.print("Atomic number $3d -> $d, $-2d", n, rc[0], rc[1])
}

View file

@ -0,0 +1,57 @@
PROGRAM "Periodic table"
DECLARE FUNCTION Entry ()
DECLARE FUNCTION MostarPos (N)
FUNCTION Entry ()
DIM Element[12]
Element[0] = 1
Element[1] = 2
Element[2] = 29
Element[3] = 42
Element[4] = 57
Element[5] = 58
Element[6] = 59
Element[7] = 71
Element[8] = 72
Element[9] = 89
Element[10] = 90
Element[11] = 103
Element[12] = 113
FOR e = 0 TO 12 'UBOUND (Element())
MostarPos (Element[e])
NEXT
END FUNCTION
FUNCTION MostarPos (N)
DIM A[7]
A[0] = 1
A[1] = 2
A[2] = 5
A[3] = 13
A[4] = 57
A[5] = 72
A[6] = 89
A[7] = 104
DIM B[7]
B[0] = -1
B[1] = 15
B[2] = 25
B[3] = 35
B[4] = 72
B[5] = 21
B[6] = 58
B[7] = 7
I = 7
DO WHILE A[I] > N
DEC I
LOOP
M = N + B[I]
R = (M \ 18) + 1
C = (M MOD 18) + 1
PRINT "Atomic number "; FORMAT$ ("###", N); " ->"; R; ","; C
END FUNCTION
END PROGRAM

View file

@ -0,0 +1,18 @@
proc ShowPosn(N); \Show row and column for element
int N, M, A, B, I, R, C;
[A:= [ 1, 2, 5, 13, 57, 72, 89, 104]; \magic numbers
B:= [-1, 15, 25, 35, 72, 21, 58, 7];
I:= 7;
while A(I) > N do I:= I-1;
M:= N + B(I);
R:= M/18 +1;
C:= rem(0) +1;
IntOut(0, N); Text(0, " -> ");
IntOut(0, R); Text(0, ", ");
IntOut(0, C); CrLf(0);
];
int Element, I;
[Element:= [1, 2, 29, 42, 57, 58, 72, 89, 90, 103];
for I:= 0 to 10-1 do ShowPosn(Element(I));
]

View file

@ -0,0 +1,37 @@
// Rosetta Code problem: http://rosettacode.org/wiki/Periodic_table
// by Jjuanhdez, 06/2022
dim Element(12)
Element(0) = 1 : Element(1) = 2
Element(2) = 29 : Element(3) = 42
Element(4) = 57 : Element(5) = 58
Element(6) = 59 : Element(7) = 71
Element(8) = 72 : Element(9) = 89
Element(10) = 90
Element(11) = 103 : Element(12) = 113
for e = 0 to arraysize(Element(),1)
MostarPos (Element(e))
next e
end
sub MostarPos (N)
dim A(7)
A(0) = 1 : A(1) = 2
A(2) = 5 : A(3) = 13
A(4) = 57 : A(5) = 72
A(6) = 89 : A(7) = 104
dim B(7)
B(0) = -1 : B(1) = 15
B(2) = 25 : B(3) = 35
B(4) = 72 : B(5) = 21
B(6) = 58 : B(7) = 7
I = 7
while A(I) > N
I = I - 1
wend
M = N + B(I)
R = int(M / 18) +1
C = mod(M, 18) +1
print "Atomic number ", N using("###"), " -> ", R, ", ", C
end sub