public
Created

  • Download Gist
brainfuck.js
JavaScript
1 2 3 4 5 6
function brainfuck(x){var p='23\n',o='',s=x.length,i=0,n=0,c=0,d=0,m={},l={},u={
},t=[];for(c=0; c<s; c++)if(x[c]=='[')t.push(c);else if(x[c]==']')u[l[c]=t.pop()
]=c;for(c=0; c<s&&i<100000; c++,i++){switch(x[c]){case'>':d++;break;case'<':d--;
break;case '+':m[d]=((m[d] || 0)+1)&255;break;case '-':m[d]=((m[d] || 0)-1)&255;
break;case'.':o+=String.fromCharCode(m[d]); break; case',':m[d]=p.charCodeAt(n++
)||0;break; case '[': m[d]||(c=u[c]);break;case ']':c=l[c]-1;break;}};return o;}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.