Search code examples
mathpermutationfactorial

Using base X, how high can I count using Y characters?


I know that the total number of permutations for a given base is the factorial... so the total number of permutations of "abc" is 3! or 3x2x1 or 6.

Obviously I'm not sure of the terminology to properly phrase my question, but I would like to find the highest numbered permutation before the "length" of it's representation increases to X characters.

For example, Using a Base 62 'alphabet', I can represent integers up to 238327 before the representation uses 4 characters instead of 3. I'd like to know the math behind finding this out, given arbitrary values for Base and Length of representation.

Essentially, "using Base-X, how high can I count using Y characters?".


Solution

  • Assuming your numbers are positive and start at 0 then you can count from 0 to X^Y - 1.

    As per your example above, 62^3 - 1 = 238328 - 1 = 238327.