问题:我正在创建一个数组或多个数组来写入值,并继续这样做,直到绘制出某个值。此代码的长视图是使用这些值将一个字母与另一个字母匹配。 (即第二次世界大战中使用的炸弹。)除此之外,它将是完全数字化的。 Bombe是一个解密者,发现一个字母能够映射到另一个字母。 (Enigma示例将在评论中发布。)我正在尝试使用此解密任何消息。
理解:我不记得很多代码,特别是因为我之前从未使用过google-apps-script。我没有基本的想法,但是一些语法不同我迷失了。 (即:而不是System.out.print();
它将是Logger.log(data);
。到目前为止,这就是我从中得到的所有内容。我已经找到了一些可以找到的代码here。
背景:这是我理解的相当多的文字,但在你标记我之前听我说,继续前进。在上面注释中发布的“Enigma example”字样下的超链接显示了我正在尝试反向执行的映射。然而,我需要创建我不记得如何创建的循环和变量。我有关于Enigma和Bombe的信息:Enigma & Bombe info。我已经在谷歌之类的网站上进行了一些搜索,但是没有任何我理解或有益于我的最终目标。我所得到的只是另一个链接,我将在评论中发布,它会向我显示一个基本的循环。
我需要帮助:我在以下方面寻求帮助:循环,变量和数组。建议对我来说是最有价值的,因为我在这里学习,而不是通过询问来完成我的工作。
想法:我有一些想法,垃圾收集器,多维数组和/或只是一系列可能性。 (参见上面的“Enigma& Bombe信息”链接。
轻松复制/粘贴:
function bombeCode1() {
var fastRotor = ["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"];
var mediumRotor = fastRotor;
var slowRotor = fastRotor;
var rows = 26;
var columns = 26;
for (var i=0; i < rows ; i++) {
Logger.log('Outer Loop: value of i : ' + i);
// Logger.log("Partition for Outer Loop");
// Logger.log(" ");
var fastRotorValue = fastRotor[i];
for (var j=0; j < columns ; j++) {
Logger.log('-Inner Loop value of j : ' +j);
//var fastRotorValue = fastRotor[i];
var medRotorValue = mediumRotor[j];
// Logger.log("---- " + fastRotorValue + " " + medRotorValue);
for (var k=0; k < 26 ; k++) {
// Logger.log('---- XXXX Third Loop value of k : ' + k);
//var fastRotorValue = fastRotor[i];
//var medRotorValue = mediumRotor[j];
var slowRotorValue = slowRotor[k];
Logger.log("---- XXXX " + fastRotorValue + " " + medRotorValue + " " + slowRotorValue);
}; //var objectNumberValuePair = {"0":"A", "1":"B", "2":"C","3":"D","4":"E","5":"F","6":"G","7":"H","8":"I",
// "9":"J","10":"K","11":"L","12":"M","13":"N","14":"O","15":"P","16":"Q","17":"R",
// "18":"S","19":"T","20":"U","21":"V","22":"W","23":"X","24":"Y","25":"Z"}
// Logger.log(slowRotorValue = objectNumberValuePair);
// Logger.log(medRoterValue = objectNumberValuePair);
// Logger.log(fastRoterValue = objectNumberValuePair);
}
}
}
答案 0 :(得分:0)
这是我稍微修改过的代码,只是为了在Logger打印输出中显示循环值。
function bombeCode1() {
var fastRotor = ["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"];
var mediumRotor = fastRotor;
var slowRotor = fastRotor;
var rows = 3;
var columns = 6;
for (var i=0; i < rows ; i++) {
Logger.log('Outer Loop: value of i : ' + i);
Logger.log("Partition for Outer Loop");
Logger.log(" ");
for (var j=0; j < columns ; j++) {
Logger.log('----Inner Loop value of j : ' + j);
var fastRoterValue = fastRotor[i];
var medRoterValue = mediumRotor[j];
Logger.log("---- " + fastRoterValue + " " + medRoterValue);
for (var k=0; k < 6 ; k++) {
Logger.log('---- XXXX Third Loop value of k : ' + k);
var fastRoterValue = fastRotor[i];
var medRoterValue = mediumRotor[j];
var slowRotorValue = slowRotor[k];
Logger.log("---- XXXX " + fastRoterValue + " " + medRoterValue + " " + slowRotorValue);
};
}
}
}
运行它,看看你的想法。我确定这不是你需要的,而是从某个地方开始。