jsがおかしい? 勝手に値が書き換わる配列
Q&A
Closed
解決したいこと
function brainfuck(code,iput,len){
let p = 0;
let m = [];
let me = [];
for(let i = 0; i < len; i++){
m.push(0);
}
me = m;
console.log(me);
let output = "";
let input_num = 0;
let indent = 0;
let indent_m = [];
for(let i = 0; i < code.length; i++){
switch(code[i]){
case "+":
m[p]++;
m[p] %= 256;
break;
case "-":
m[p]--;
m[p] %= 256;
break;
case ">":
p++;
p %= len;
break;
case "<":
p--;
p %= len;
break;
case ".":
output += String.fromCodePoint(m[p]);
break;
case ",":
m[p] = iput.codePointAt(input_num) % 256;
input_num++;
break;
case "[":
indent_m.push(i);
indent++;
break;
case "]":
if(m[p] !== 0){
i = indent_m.pop();
}
indent--;
break;
}
}
return output;
}```
これでもおかしくなります
0