Skip to content

Instantly share code, notes, and snippets.

@mov-78
Last active March 3, 2017 01:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mov-78/670c4727b18a2c767aeb9874cea390bd to your computer and use it in GitHub Desktop.
Save mov-78/670c4727b18a2c767aeb9874cea390bd to your computer and use it in GitHub Desktop.
a 430byte brainfuck interpreter
p=process;j=require('path').join;r=require('fs').readFileSync;u='utf8';d=__dirname;v=p.argv;e=[];i=v[3]?r(j(d,v[3]),u).split(''):[];s=r(j(d,v[2]),u);t={'<':'c--;','>':'c++;','+':'m[c]++;','-':'m[c]--;',',':'i[0]&&(m[c]=i.shift().charCodeAt(0)%0xFF);','.':'p.stdout.write(String.fromCharCode(m[c]));','[':'while(m[c]){',']':'}'};m=new Array(0xFFFF).fill(c=0);for(n of s.replace(/[^<>\-+,.[\]]/g,''))e.push(t[n]);eval(e.join(''));
@mov-78
Copy link
Author

mov-78 commented Mar 3, 2017

$ node BRAIN_FUCKED.js source.bf [data.txt]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment