What's a good way for figuring out all possible words of a given length

后端 未结 12 1776
一生所求
一生所求 2021-02-04 17:27

I\'m trying to create an algorithm in C# which produces the following output strings:

AAAA
AAAB
AAAC
...and so on...
ZZZX
ZZZY
ZZZZ

What is the

12条回答
  •  逝去的感伤
    2021-02-04 18:10

    javascript!

    var chars = 4, abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", top = 1, fact = [];
    for (i = 0; i < chars; i++) { fact.unshift(top); top *= abc.length; }
    for (i = 0; i < top; i++)
    {
        for (j = 0; j < chars; j++) 
            document.write(abc[Math.floor(i/fact[j]) % abc.length]);
        document.write("
    \n"); }

提交回复
热议问题