Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
BrainFu*k
function exe(){
document.getElementById("disp").innerText = "";
var mem = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var mempos=0;
var code = document.getElementById("z").value;
var codepos = 0;
while(codepos<=code.length){
switch(code.charAt(codepos)){
case ">":
mempos++;
break;
case "<":
mempos--;
break;
case "+":
mem[mempos]++;
break;
case "-":
mem[mempos]--;
break;
case ".":
document.getElementById("disp").innerText += String.fromCharCode(mem[mempos]);
alert(mem[mempos])
break;
case ",":
mem[mempos] = parseInt(document.getElementById("y").value);
break;
case "[":
if(mem[mempos]==0){
kakko=0;
while(true){
codepos++;
if(code[codepos]=="]"&&kakko==0){
break;
}
if(code[codepos]=="["){
kakko++;
}
if(code[codepos]=="]"&&kakko>0){
kakko--;
}
}
}
break;
case "]":
if(mem[mempos]!=0){
kakko=0;
while(true){
codepos--;
if(code[codepos]=="["&&kakko==0){
break;
}
if(code[codepos]=="]"){
kakko++;
}
if(code[codepos]=="["&&kakko>0){
kakko--;
}
}
}
break;
}
codepos++;
}
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src=script.js></script>
<title>test</title>
</head>
<body>
<form >
<input type="text" id="z" placeholder="code">
<input type="button" onclick="exe();" >
<input type="text" id="y" placeholder="input">
</form>
<div id="disp">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment