当我猜这封信时,它一直在申请这封信。例如 说这个词是单词,然后我会猜到字母d,然后就可以了 DDDDD。它使用那个字母作为整个单词。这是我的代码。
function arrayAddition(arr) {
var arrMax = Math.max.apply(Math, arr);
var found = false;
function recArrAdd(sub, arr) {
if (found) return true;
if (arr.length > 0) {
var arrSum = sub.concat(arr[0]).reduce(function(prev, curr) { return prev + curr;});
if (arrSum === arrMax){
if (arr[0] != arrMax){
found = true;
return found;
}
};
recArrAdd(sub.concat(arr[0]), arr.slice(1));
recArrAdd(sub, arr.slice(1));
}
return found;
}
return recArrAdd([], arr);
}
console.log("[1,2,3] -> "+arrayAddition([1,2,3]));
console.log("[1,2,5] -> "+arrayAddition([1,2,5]));
console.log("[1,2,5,4,20,8] -> "+arrayAddition([1,2,5,4,20,8]));
console.log("[1,2,5,4,21,8] -> "+arrayAddition([1,2,5,4,21,8]));
console.log("[1,3,5,4,25,8,14] -> "+arrayAddition([1,3,5,4,25,8,14]));
console.log("[1,3,5,4,45,8,14] -> "+arrayAddition([1,3,5,4,45,8,14]));
答案 0 :(得分:0)
这部分是罪魁祸首:
for re in range(0, len(myword)):#For statement to loop over the answer (not really over the answer, but the numerical index of the answer)
fake[re] = guess #change the fake to represent that, EACH TIME IT OCCURS
print(''.join(fake))
此代码用fake
guess
中的每个元素