计算第N排列一步?

编程入门 行业动态 更新时间:2024-10-11 13:31:03
本文介绍了计算第N排列一步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有AZ,并通过信件的一个char [26]对于嵌套声明我像生产序列的列表:

I have a char[26] of the letters a-z and via nested for statements I'm producing a list of sequences like:

aaa, aaz... aba, abb, abz, ... zzy, zzz.

目前,该软件被写入生成所有可能的值,从AAA-ZZZ列表,然后保持索引,并经过对他们每个人进行操作。

Currently, the software is written to generate the list of all possible values from aaa-zzz and then maintains an index, and goes through each of them performing an operation on them.

名单显然是大的,它不是大得离谱,但它得到的地步内存占用过大(也有正在看着其他地区,但是这是一个我已经得到了)。

The list is obviously large, it's not ridiculously large, but it's gotten to the point where the memory footprint is too large (there are also other areas being looked at, but this is one that I've got).

我想产生一个公式,我能保持的索引,但废除序列的列表,并计算基于所述当前索引的当前序列(如序列之间操作之间的时间长)。

I'm trying to produce a formula where I can keep the index, but do away with the list of sequences and calculate the current sequence based on the current index (as the time between operations between sequences is long).

例如:

char[] characters = {a, b, c... z}; int currentIndex = 29; // abd public string CurrentSequence(int currentIndex) { int ndx1 = getIndex1(currentIndex); // = 0 int ndx2 = getIndex2(currentIndex); // = 1 int ndx3 = getIndex3(currentIndex); // = 3 return string.Format( "{0}{1}{2}", characters[ndx1], characters[ndx2], characters[ndx3]); // abd }

我试着锻炼用的子集一个小例子( ABC),并试图索引,使用模师,但我有今天的麻烦思考,我很为难。

I've tried working out a small example using a subset (abc) and trying to index into that using modulo division, but I'm having trouble thinking today and I'm stumped.

我不要求回答,只是任何形式的帮助。也许在一个正确的方向踢

I'm not asking for an answer, just any kind of help. Maybe a kick in the right direction?

推荐答案

提示:想想你将如何打印数在基座26,而不是基体10,并用字母,而不是数字。是什么?在任意基地显示了一些一般的算法

Hint: Think of how you would print a number in base 26 instead of base 10, and with letters instead of digits. What's the general algorithm for displaying a number in an arbitrary base?

扰流:(向右滚动查看)

int ndx1 = currentIndex / 26 / 26 % 26; int ndx2 = currentIndex / 26 % 26; int ndx3 = currentIndex % 26;

更多推荐

计算第N排列一步?

本文发布于:2023-11-29 07:04:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645685.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:排列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!