The reason for this is study / learning. To know / apply programming techniques and concepts, transforming something "material" into "application".
I received a video on WhatsApp, where mixed colored balls were separated by colors passing through the pins. Either it was a lot of mechanical technology or fake video. In the end, it was a fake video, where a graphic design reproduced a Galton Board for a study paper.
Wanting to know more, I found it in the Wikipedia , and I would like to turn it into a "program".
Theboardbasicallysimulatesthe"Central Limit Theorem" ( link ): The theorem describes the distribution of the mean of a random sample of a population with finite variance.
Idea:
Startingwiththeboard,Idecidedtocreateanarray,whereIhavemalhas
andpinos
,formingaline:
-------Malha------->[P1][P2][P3][P4][P5]...
Pinvalues:
Astheoddsoftheballsgoingdownisalwaysgreaterfromthecentertothesides,Icreatedthepinswithvalues,andthebigger,morechancesof"continue " there. But also, since the pins are "interleaved" and not aligned vertically , I also considered that.
Creating the meshes:
// Definicoes
$qtdMalhas = 15;
$qtdPinos = 15;
// Auxiliares malhas/pinos
$am = $ap = 0;
// Criando as malhas e seus pinos
while ($am <= $qtdMalhas) {
while ($ap < $qtdPinos) {
if ($ap < ($qtdPinos/2)) {
if ($am % 2 == 0) {
$m[$am][$ap] = $ap;
} else {
$m[$am][$ap] = $ap+1;
}
} else {
if ($am % 2 == 0) {
$m[$am][$ap] = $qtdPinos-$ap-1;
} else {
$m[$am][$ap] = $qtdPinos-$ap;
}
}
$ap++;
}
$ap = 0;
$am++;
}
Mesh structure:
Considering the array basically in the following format:
$m[0][0]-$m[0][1]-$m[0][2]-$m[0][3]-$m[0][4]...
$m[1][0]-$m[1][1]-$m[1][2]-$m[1][3]-$m[1][4]...
$m[2][0]-$m[2][1]-$m[2][2]-$m[2][3]-$m[2][4]...
$m[3][0]-$m[3][1]-$m[3][2]-$m[3][3]-$m[3][4]...
$m[4][0]-$m[4][1]-$m[4][2]-$m[4][3]-$m[4][4]...
...
Printing the mesh:
// Zera auxiliares malhas/pinos
$am = $ap = 0;
// Imprime a malha
while ($am < $qtdMalhas) {
echo '<br>|';
while ($ap < $qtdPinos) {
echo $m[$am][$ap].'|';
$ap++;
}
$ap = 0;
$am++;
}
Result:
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
|1|2|3|4|5|6|7|8|7|6|5|4|3|2|1|
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
|1|2|3|4|5|6|7|8|7|6|5|4|3|2|1|
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
|1|2|3|4|5|6|7|8|7|6|5|4|3|2|1|
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
|1|2|3|4|5|6|7|8|7|6|5|4|3|2|1|
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
|1|2|3|4|5|6|7|8|7|6|5|4|3|2|1|
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
|1|2|3|4|5|6|7|8|7|6|5|4|3|2|1|
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
|1|2|3|4|5|6|7|8|7|6|5|4|3|2|1|
|0|1|2|3|4|5|6|7|6|5|4|3|2|1|0|
Could you knit in other ways?
Yes, using zero and one for the pins but I believe that it would have more work to draw according to the probability of each pin. Among other ways.
With the mesh ready, how can I "pass the balls"?
The idea would be to draw between the values of the pins below, considering that the chances of it staying closer to the highest value pin , ie a draw with different probabilities, and thus get the result as the "Galton Tray".
Feel free to post your own way.