自动递增字母数字序列

自动递增字母数字序列

问题描述:

在生成字母数字序列时需要算法的指针.要求如下.

Need pointer for algorithm on generating alphanumeric sequence. The requirement is as follows.

只能使用0-9,A-Z和a-z字符.最初,该序列仅以一个字符开始,当序列用尽时将变为两个字符,并且类似地,当上一个序列用尽时该序列将递增.

Only 0-9, A-Z and a-z characters can be used. Initially the sequence will start with only one character and when the sequence has been exhausted will it go to two characters and similarly the sequence will be incremented when the previous sequence has been exhausted.

序列示例如下

一个字符序列

0 1 2 .. 9 A B .. Z a b .. z

0 1 2 .. 9 A B .. Z a b .. z

现在,一个字符序列已用尽.然后将开始一个2位数的序列.

Now the one character sequence has been exhausted. Then a 2 digit series will start.

00 01 02 .. 09 0A 0B ..0Z 0a 0b ..0z 10 11 ..19 1A ..1Z 1a 1b .. zz

00 01 02 .. 09 0A 0B .. 0Z 0a 0b .. 0z 10 11 .. 19 1A .. 1Z 1a 1b .. zz

在用完两个字符系列之后,将开始如下所示的三个字符系列

After two characters series has been exhausted then 3 character series will start as given below

000 ... zzz

000 ... zzz

该系列将一直生成,直到用完12个字符系列为止.

And the series will generate till the 12 character series has been exhausted.

有人可以帮助我指向某个链接或向我建议这样做的机制吗?

Can anybody help me point to some link or suggest me the mechanism to do it?

我正在尝试用PHP做到这一点.

I am trying to do this in PHP.

谢谢

Python:

digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

def NthStr(n):
    str=digits[n%len(digits)];
    while n>=len(digits):
        n=(n/len(digits) - 1)
        str=digits[n%len(digits)]+str
    return str

尝试一下(减少位数,因此您可以看到模式): https://ideone.com/rZEV1m

Try it (with fewer digits, so you can see the pattern): https://ideone.com/rZEV1m

我想这很容易翻译成PHP

I imagine this would be pretty easy to translate into PHP