所有可能的组合字符串

所有可能的组合字符串

本文介绍了所有可能的组合字符串 - 速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个jquery脚本,它可以生成所有可能的字符串组合,其中包含数字和小写字母。我只想要字符串10个字符长,所以我扔了一个if语句控制。



对于那些感兴趣的,这里的脚本:

  $(document).ready(function(){

var parts = ['a','b','c', 'd', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', '0','p , 'q', 'R', 'S', 'T', 'U', 'v', 'W', 'X', 'Y', 'Z', '1', '2', '3','4','5','6','7','8','9','0'];
var url =;
$ b $ (var c = 0; b for(var b = 0; b< parts.length; b ++) (var d = c + 1; d for(var e = d + 1; e< parts (var f = e + 1; f for(var g = f + 1; g for(var h = g + 1; h for(var i = h + 1; i< parts.length; (var j = i + 1; j< parts.length; j ++){
url = parts [a] + parts [b] + parts [c] + parts [d ] +份[E] +份并[f] +份[G] +份并[h] +份[I] +份[D];
if(url.length === 10){
$(#URLs)。append(url +',');
}
}
}
}
}
}
}
}
}
}
}
}

});

每个字符都有一个for循环。如果你只想要3个字符的字符串,只能使用3个嵌套的字符。



这可能不雅观,但它的工作原理。我的问题是速度/崩溃。



当然,试图通过浏览器运行这是一个坏主意。什么是更好的程序/语言/设置速度?我明白,无论如何,我可能受到我的CPU能力的约束,暴力强制总是缓慢。



如果有一个服务可以做同样的事情,猜测这也可以。

解决方案

你不会有存储输出的地方。你说的是3.656e + 15的组合,所以你把它附加到DOM元素的方法是行不通的。

即使你使用C / C ++或Java,你还在谈论的东西可能是不可行的,因为你的存储容量。如果你只是动态地提交它们(而不是存储它们),那么提交很多请求就会花费很长时间。我不认为你会在这里尝试完成的任何(阴暗的)事情成功。


I've created a jquery script that generates all possible combinations of a string, where numbers and lower case letters are involved. I only want strings 10 characters long, so I threw in an if statement controlling that.

For those interested, here's the script:

$(document).ready(function(){

    var parts = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0'];
    var url = "";

for (var a = 0; a < parts.length; a++) {
    for (var b = 0; b < parts.length; b++) {
        for (var c = 0; c < parts.length; c++) {
            for (var d = c + 1; d < parts.length; d++) {
                for (var e = d + 1; e < parts.length; e++) {
                    for (var f = e + 1; f < parts.length; f++) {
                        for (var g = f + 1; g < parts.length; g++) {
                            for (var h = g + 1; h < parts.length; h++) {
                                for (var i = h + 1; i < parts.length; i++) {
                                    for (var j = i + 1; j < parts.length; j++) {
                                            url = parts[a]+parts[b]+parts[c]+parts[d]+parts[e]+parts[f]+parts[g]+parts[h]+parts[i]+parts[j];
                                            if (url.length === 10) {
                                                $("#URLs").append(url+', ');
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

});

There's a for loop per character spot. If you just want strings 3 char's long, use only 3 nested for's.

It may be inelegant, but it works. My issue is speed/crashes.

Naturally, trying to run this through a browser is a bad idea. What would be a better program/language/set up for speed? I understand that I'm probably bound by my CPU's capabilities no matter what, and that brute forcing is always slow.

If there's a service that does this same thing, I guess that would work too.

解决方案

You're not going to have a place to store the output. You're talking about 3.656e+15 combinations, so your approach of appending that to a DOM element is not going to work.

Even if you used C/C++ or Java, you're still talking about something that's probably infeasible for your storage capacity. And it would take way to long to submit that many requests if you just dynamically submitted them (vs. storing them). I don't think you'll be successful with whatever (shady?) thing you're trying to accomplish here.

这篇关于所有可能的组合字符串 - 速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:52