Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.