How many possible URLs can you make with the following characters?

I want to make a short URL service for 2 million assets, but I want to use the shortest possible number of characters.

What is a mathematical equation that I will need to use to understand this? I know this has something to do with factorials, right?

+3
source share
6 answers

This is not a factor problem, but an exponential one.

If xis the number of possible characters, you need to solve the following equation for y:

x^y = 2000000

alpha [0-9A-Za-z], 62 . , :

     62^y = 2000000
y*log(62) = log(2000000)
        y = log(2000000) / log(62)
        y = 3.5154313828...

, 3.5 URL-, 4. , URL-, , .

. URL . URL . .

+11

@jheddings , . , . URL- 1 y . :

x + x ^ 2 + x ^ 3 +... + x ^ y = 2000000

, :

x + x ^ 2 + x ^ 3 +... + x ^ y = x * (x ^ y - 1)/(x-1) = 2000000

x - . , , (26 + 26 + 10 = 62.)

:

2000000 = (62^(y+1) - 62)/(62-1)
2000000 = (62^(y+1) - 62)/(61)
2000000 * 61 = 62^(y+1) - 62
122000000 = 62^(y+1) - 62
122000000 + 62 = 62^(y+1)
122000062 = 62^(y+1)
log(122000062) = (y+1)
log(122000062) / log(62) = y+1
4.511492 = y+1
3.511492 = y

, , 3.5 , 4. , . ( 2) .

+5

URL = ( ID), ( URL-)

, ( 26), URL- http://domain.com/XXXXX ( 5 ), 26 ^ 5 = 11 881 376 URL.

, 52, 52 ^ 5 = 380 204 032 URL ..

+1

, , .

? 36 (5 2mil +)

? 62 (4 )

(, i/l 0/o)? 32 ( 5 )

+1

You can often solve this problem without mathematical magic.

26 + 26 + 10 = 62 characters

Try 1. 62 = 62
Try 2. 62*62 = 3,844
Try 3. 62*62*62 = 238,328
Try 4. 62*62*62*62 = 14,776,336

So 4 is your answer :)

+1
source

According to the HTTP / URI Spec, you can optionally use the following "unconditional characters": ALPHA / DIGIT / "-" / "." / "_" / "~"

This adds an extra 4 characters to your radius and therefore

Math.log(2000000) / Math.log(66) = 3.4629721616408813

Although this still means that you end up with a maximum of 4 character URLs.

0
source

Source: https://habr.com/ru/post/1721609/


All Articles