Electronic distribution algorithm

1

I'm trying to think of a different way of doing electronic distribution. The way I did it was this: display the amount of electrons in each layer. However, in the distribution that I want (1s² 2s² 2p 6 ...) the order of the layers are not respected.

The distribution I want is made according to the Linus Pauling diagram , which has this order here : 1s2, 2s2, 2p6, 3s2, 3p6, 4s2, 3d10, 4p6, 5s2, 4d10, 5p6, 6s2, 4f14, 5d10, 6p6, 7s2, 5f14, 6d10, 7p6. The number after the letter is the number of electrons in each sub-level (represented by the letters) and the number before the letter the layer / level.

I had also done one of those things that I proposed, however, it was very poorly written.

I put these values from the diagram as a string in an array and then I used and str_replace() . That is, I did not do an "algorithm itself."

For those who do not understand electronic distribution and want to help, I will distribute an atom of:

  

Atomic number 10 -> 1s² 2s² 2p 6
  Atomic number 11 -> 1s² 2s² 2p 6 3s¹
  Atomic number 14 -> 1s² 2s² 2p 6 3s² 3p²

That is, just follow that order from the diagram above, not having to fill all the vacancies for the electrons, but never exceeding the limit. So if anyone can help me, finding a way to do the distribution the way I mentioned it, I would appreciate it.

Now, I did the part that verifies that the distribution ends up with 4 or 9 electrons in the sub-level "D", and if so, it removes an electron from the nearest sub-level "S" and sends it to "D"):

<?php

if ($_GET['atomic_n']) {

$arr_1 = array("1s2", "2s2", "2p6", "3s2", "3p6", "4s2", "3d10", "4p6", "5s2", "4d10", "5p6", "6s2", "4f14", "5d10", "6p6", "7s2", "5f14", "6d10");
$arr_2 = substr_replace ($arr_1, "", 0, 2);
$arr_3 = substr_replace ($arr_1, "", 2);


 $eletrons = $_GET['atomic_n'];
 $contador = 0;

    for ($i = 0; $i<=17; $i++) {

        if ($contador < $eletrons) {

            $contador += $arr_2[$i];

            if ($contador < $eletrons) {

                $arr_4[] = "$arr_3[$i]<sup>".$arr_2[$i]."</sup>";

             } else {

               $arr_4[] = $arr_3[$i]."<sup>".($arr_2[$i]-$contador+$eletrons)."</sup>";

             }
   }
}

  $k = 0;
  while ($arr_4[$k]) {
  $ultimo_termo = $k;
  $k++;
  }

$arr_excl = substr_replace ($arr_4, "", 0, 1);

$eletrons_final_2 = substr_replace ($arr_4, "", 0, 2);
$eletrons_final = str_replace ("<sup>", "", $eletrons_final_2);

$subnivel_2 = preg_replace ("/[^a-z]/", "", $arr_4);
$subnivel = str_replace ("sup", "", $subnivel_2);
$nivel = substr_replace ($arr_4, "", 1);

if ( end($arr_excl) == "d<sup>4</sup>" || end($arr_excl) == "d<sup>9</sup>" ) {

 $r = $ultimo_termo;

        while ($r > 0) {


                if ($subnivel[$r] == "s") {

                    $eletrons_final[$r] -= 1;
                    $eletrons_final[$ultimo_termo] +=1;
                    break;

                }

        $r--;

        }

for ($w = 0; $w <= $ultimo_termo; $w++) {

    echo $nivel[$w].$subnivel[$w]."<sup>".$eletrons_final[$w]."</sup>"."<br>";

}



    } else {

      foreach ($arr_4 as $k => $v){
              echo "$v<br>";

      }

    }

}

?>
    
asked by anonymous 17.10.2014 / 04:28

0 answers