Hello!

Please tell me the algorithm for calculating the catalog, consisting of a sequence of numbers.

The directory has the form: /X/Y/Z/ , where X, Y, Z folders are names.

The maximum number of folders in a subfolder is 5. Those. The final directory will be: /5/5/5/

I have a unique folder id. I need to know which way the number will match, if the number of folders in the subfolder is no more than 5. For example, if the folder id is 15 , the path will be 0/3/0/ . For folder 29, the path will be 1/0/3 0/5/4/ , for 32 1/0/3 , etc.

I try the remainder of the division: Number = 17. The path is calculated by dividing the number by the specified maximum number of folders in the subfolder. It turns out 17/5 = integer 3, the remainder 2. So the path will be 0/3/2/ .

But how to calculate if the number will be for example 37?

Thank you in advance!

    2 answers 2

     $id = 37; $x = floor($id / 5 / 5); $y = floor($id / 5 - $x * 5); $z = $id - $x * 5 * 5 - $y * 5 

      I have not worked with PHP for a long time. But Google suggests that there is a function base_convert, which allows you to convert between two arbitrary number systems.

      Maybe you should translate this function to your number in the five-fold number system, and dismantle the result into characters?

      And by the way, it seems you have a little confusion in the conditions of the problem. If the digit "5" is admissible as a result, then this is already a six-dimensional number system (five digits + zero) and it is necessary to divide by 6, and not by five.