第0题地址:https://fun.coolshell.cn/first.html
毫无头绪……
通过搜索,没想到Brainfuck是一种编程语言……
因此,用JavaScript写了一个解释器。
直接在浏览器控制台运行即可,得到第1题地址:https://fun.coolshell.cn/welcome.html
var code = "++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>++++++++++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>>>>>>>-.+<<<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<>>>>>>>>>>>>+++.---<<<<<<<<<<<<>>>>>>>>>>>>>>-.+<<<<<<<<<<<<<<>>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>--.++<<<<<<>>>>>>>>>>>>>.<<<<<<<<<<<<<>>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<<>>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<<>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<.";
var array = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var point = 0;
var stack = [];
var answer = "https://fun.coolshell.cn/";
for (var i = 0; i < code.length; ++i) {
switch (code[i]) {
case ">":
++point;
break;
case "<":
--point;
break;
case "+":
++array[point];
break;
case "-":
--array[point];
break;
case ".":
console.log(String.fromCharCode(array[point]));
answer += String.fromCharCode(array[point]);
break;
case "[":
if (array[point] == 0) {
i = stack.pop();
} else if(stack[stack.length - 1] != i) {
stack.push(i);
}
break;
case "]":
if (array[point] == 0) {
stack.pop();
} else {
i = stack[stack.length - 1];
}
break;
}
// console.log(point, a);
}
console.log(answer);
收获:只要约定得当,什么符号都可以成为一门语言。