Skip to content

Instantly share code, notes, and snippets.

@DanielRapp

DanielRapp/bf.js Secret

Created February 22, 2012 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielRapp/a4a2486c715205aeb52b to your computer and use it in GitHub Desktop.
Save DanielRapp/a4a2486c715205aeb52b to your computer and use it in GitHub Desktop.
Brainfuck
with(process)for(a=[k=j=p=0],l=[];c=argv[2][k];k++){c=='['&&l.unshift(a[p]&&l[0]!=-1?k:-1)
c==']'&&(a[p]&&l[0]>=0?k=l[0]:l.splice(0,1))
if(l[0]!=-1){p+=c=='>'?1:c=='<'&&-1
s=c=='+'?1:c=='-'&&-1
a[p]=a[p]==undefined?s:a[p]+s
c=='.'&&stdout.write(String.fromCharCode(a[p]))
c==','&&(a[p]=argv[3].charCodeAt(j++))}}
@DanielRapp
Copy link
Author

Here's a more readable version: https://gist.github.com/4eecbc79053032a5d9eb

Save this as bf.js and run with:
node bf.js "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."

Simple cat program:
node bf.js ",[.,]" "Hello World!"

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