问题描述
我想增加一些数组值:
INT计数器[] = {0,0,0,0,0,0,0,0};
如果数目在位置0值达到25,然后在1位的值被加1,并且位置0复位为0等等 - 当索引位置2到25它加1的位置3,并复位它自己的值改为0。
我做了一些base26递增 - 生成的字母一个字母给定数量的所有组合。理想情况下,我想这无限的工作(理论上) - 一个新的数组索引追加当最后一个值达到25
我正在此previous问题涉及到项目 - 可能澄清我想要做的事: 的
这里的code我在一分钟:
//设置变量。
字符串新词;
INT计数器[] = {0,0,0,0,0,0,0,0};
字符串base26 [] = {\"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\"};无效设置(){
//初始化串口通信:
Serial.begin(9600);
}空隙环(){
INT I = 0;
//重置或增加计数器。
如果(计数[一] == 25){
计数器由[i] = 0;
计数器[I + 1] ++;
}
其他{
计数器[I] ++;
}
新词=字母(计数器[I]);
Serial.print(+新词新义的'\\ n');
延迟(100);
我++;
如果(ⅰ大于7){
I = 0;
}
}包含字母(INT计数器){
串newword;
的for(int i = 0; I< = 7;我++){
newword + = base26 [窗口];
}
返回newword;
}
使用的。
I'm trying to increment some array values:
int counter[] = {0,0,0,0,0,0,0,0};
If the value of the number in position 0 reaches 25, then the value in position 1 is incremented by 1, and position 0 reset to 0. And so on - when index position 2 reaches 25 it increments position 3 by 1, and resets it's own value to 0.
I'm doing some base26 incrementing - generating all the combinations of letters for a given number of letters. Ideally I'd like this to work infinitely (in theory) - a new array index is appended when the last value reaches 25.
I'm working on the project which this previous question relates to - might clear up what I'm trying to do: Every permutation of the alphabet up to 29 characters?
Here's the code I have at the minute:
// Set the variables.
String neologism;
int counter[] = {0,0,0,0,0,0,0,0};
String base26[] = {"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"};
void setup() {
// Initialize serial communication:
Serial.begin(9600);
}
void loop() {
int i = 0;
// Reset or increment the counter.
if (counter[i] == 25) {
counter[i] = 0;
counter[i+1]++;
}
else {
counter[i]++;
}
neologism = letters(counter[i]);
Serial.print(neologism+'\n');
delay(100);
i++;
if(i>7) {
i=0;
}
}
String letters(int counter) {
String newword;
for(int i=0; i <= 7; i++) {
newword += base26[counter];
}
return newword;
}
Use class java.math.BigInteger.
这篇关于递增数组值 - 的Arduino的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!