Periodic table: Difference between revisions

Line 1,165:
Element 103 (Lr) is at 9, 18
Element 113 (Nh) is at 7, 13
</pre>
 
=={{header|PHP}}==
{{trans|Nascom BASIC}}
<syntaxhighlight lang="php">
<?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;
}
?>
</syntaxhighlight>
{{out}}
<pre>
1 -> 1 1
2 -> 1 18
29 -> 4 11
42 -> 5 6
57 -> 8 4
58 -> 8 5
72 -> 6 4
89 -> 9 4
90 -> 9 5
103 -> 9 18
</pre>
 
511

edits