Hello.
I do not even know how to ask a question. The bottom line is this. I tried and try to write a function that would count how many unique numbers are in a certain number. I want the function to display as in the list below:
- $ nb = 0; // the output should be 0
- $ nb = 1; // the output should be 1
- $ nb = 2; // the output should be 2
- ...
- $ nb = 13; // the output should be 13
- $ nb = 14; // output should be 0 0
- $ nb = 15; // output should be 0 1
- $ nb = 16; // the output should be 0 2
- ...
- $ nb = 27; // the output should be 0 13
- $ nb = 28; // output should be 1 0
- $ nb = 29; // the output should be 1 1
- $ nb = 30; // the output should be 1 2
- ...
- $ nb = 196; // output should be 0 0 0
- $ nb = 197; // output should be 0 0 1
- $ nb = 198; // output should be 0 0 2
- ...
- $ nb = 392; // output should be 1 0 0
- $ nb = 393; // output should be 1 0 1
- $ nb = 393; // the output should be 1 0 2
- ...
- $ nb = 2743; // the output should be 13 13 13
- $ nb = 2744; // output should be 0 0 0 0
- $ nb = 2745; // output should be 0 0 0 1
- $ nb = 2746; // output should be 0 0 0 2
- ...
And I get some kind of logical error, that when entering the number 392, 1 14 -196 is output, and at 393 1 14 -195 well, etc. And when you enter a larger and smaller number in the $nb variable, a logical error is also output. For example, when I enter the number 15, I get -0 -12 -181 . I tried to do all this dynamically, but in 5 days I practically did not move anywhere.
Here is the function itself:
// на это число делю $count = 14; // число // минимальное возможное число при $count'е 14 может быть только 196 // максимальное возможное число при $count'е 14 может быть только 391 $nb = 391; // предыдущая так сказать граница $pr_nb = explode('.', log($numb, $count))[0]; $pr_nb = pow($count, $pr_nb); // первый остаток $balance1 = $nb - $pr_nb; // второй остаток, предпоследнее число $balance2 = explode('.', $balance1 / $count)[0]; $balance2a = explode('.', log($balance2, $count))[0]; // третий остаток, последнее число $balance3 = $balance1 - (explode('.', $balance2 * $count)[0] * explode('.', log($balance1, $count))[0]); // четвёртый остаток, это 3-я цифра с конца $balance4 = explode('.', $balance1 / (pow($count, 2)))[0]; echo '<h1 style="color:red;">['.$balance4.'] ['.$balance2.'] ['.$balance3.']</h1>'; The principle is that if the number in the $nb variable is between values 14 in the 2nd degree, then this number will be recorded with 3 numbers (from 0 0 0 to 13 13 13 ). If in the 3rd degree, then 4 (from 0 0 0 0 to 13 13 13 13 ), if in the 4th degree, then 5 digits (from 0 0 0 0 0 to 13 13 13 13 13 ) etc.
I know that the code is just awful. Therefore, I ask for your help.