获取所有可能的单词组合 [英] Get all possible word combinations

查看:27
本文介绍了获取所有可能的单词组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 n 个单词的列表(比方说 26 个).现在我想获得所有可能组合的列表,但每行最多有 k 个单词(假设为 5 个)

I have a list of n words (let's say 26). Now I want to get a list of all possible combinations, but with a maximum of k words per row (let's say 5)

所以当我的单词列表是:aaa, bbb, ..., zzz我想得到:

So when my word list is: aaa, bbb, ..., zzz I want to get:

aaa
bbb
...
aaabbb
aaaccc
...
aaabbbcccdddeeefff
aaabbbcccdddeeeggg
...

我想让它可变,以便它可以处理任何 n 或 k 值.应该没有单词是两次,每一个组合都需要采取(即使有很多).

I want to make it variable, so that it will work with any n or k value. There should be no word be twice and every combinations needs to be taken (even if there are very much).

我怎么能做到这一点?

感谢您的回答.这不是一项任务.只是我忘记了密码的组合,我想确保我已经测试了所有组合.虽然我没有 26 个密码部分,但这让我更容易解释我想要什么.

Thank you for your answers. It is not an assignment. Is is just that I forgot the combinations of my password and I want to be sure that I have all combinations tested. Although I have not 26 password parts, but this made it easier to explain what I want.

如果还有其他人遇到同样的问题,此链接可能会有所帮助:
c#生成单词组合数组

If there are other people with the same problem, this link could be helpfull:
Generate word combination array in c#

推荐答案

你可以看看 这个

但是,如果您需要获得大量的组合(数以千万计),您应该使用惰性求值来生成组合.

However, if you need to get large numbers of combinations (in the tens of millions) you should use lazy evaluation for the generation of the combinations.

这篇关于获取所有可能的单词组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆