组合....笛卡尔积?
我想使用给定字符的组合生成文件夹 即带有字符组合的 8 个字符文本:abcdefghijklmnopqrstuvwxyz1234567890。 对于 8 个字符的组合,有 2821109907456 种可能性。我想按 10,000 的范围对它们进行分组。
我需要将这些文件夹放入相关范围文件夹中,即 “aaaaaaa1 - aaaaaaa9”是 9 个组合的范围,并且将在此范围文件夹中创建文件夹“aaaaaaa3”。
我想使用 C# 代码,为我的方法指定一个文件夹名称,即“aaaaaaa3”,并返回相关文件夹范围,即“aaaaaa1 - aaaaaaa9”,应将其保存在其中。
问题:我需要 C# 代码来执行此操作!
I want to generate folders using combinations of given characters
i.e. 8 character text with combination of characters: abcdefghijklmnopqrstuvwxyz1234567890.
For the 8 characters combinations there are 2821109907456 possibilities. I want to group these by range of 10,000.
I need to put these folders in relevant range folders i.e.
'aaaaaaa1 - aaaaaaa9' is a range of 9 combinations and a folder 'aaaaaaa3' will be created in this range folder.
I want to use c# code, give my method a folder name i.e. 'aaaaaaa3' and be returned the relevant folder range i.e. 'aaaaaa1 - aaaaaaa9' where it should be saved.
Question: I need c# code to do this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您实际上使用的是 36 基表示法(36 位数字用于表示数字)。
因此,处理这些文件名的最简单方法是将它们转换为十进制表示法,然后除以 10000。
如下所示:
并使用 sum 来确定目标范围。只需将
sum / 10000
转换回 36 进制表示法即可。你就完成了。You are actually using 36-base notation (36 digits are used to represent numbers).
So the easiest way to handle these filenames is to convert them to decimal notation and then just divide by 10000.
Something like this:
And use sum to determine the target range. Just convert
sum / 10000
back to 36-base notation. And you are done.从一开始,我们似乎需要计算字母数字序列的范围,这意味着将它们转换为数字并返回。通用基转换器似乎是第一个逻辑步骤:
然后,您需要代码来计算范围:
最后,将 BaseConverter 和 NumericRangeFactory 类结合在一起,以使用此示例静态方法解决问题:
我还没有测试过这个,但我认为这个概念是可靠的。
From the beginning, it looks like we're going to need to compute ranges of alphanumeric sequences, which means converting them to numbers and back. An all-purpose base converter seems like the first logical step:
Then, you'll need the code to compute your ranges:
Finally, tie the BaseConverter and NumericRangeFactory classes together to solve the problem with this sample static method:
I haven't tested this, but I think the concept is solid.
要使范围更大(最简单的是 36 的幂),请缩短前缀并使开头和结尾重复几次:
(0, 6)
..."aa"
...“00”
。要缩短范围,请执行以下操作:然后:
To make the range larger, most easily in powers of 36, make the prefix shorter and make the start and end repeat themselves a few times:
(0, 6)
..."aa"
..."00"
. To make the range shorter, do something like this:Then: