Skip to content

Instantly share code, notes, and snippets.

@rdebath
Created September 18, 2015 22:58
Show Gist options
  • Save rdebath/3060affe89a739cf8624 to your computer and use it in GitHub Desktop.
Save rdebath/3060affe89a739cf8624 to your computer and use it in GitHub Desktop.
Brainfuck interpreter in ruby
eval 'm=Hash.new(p=0);'+ARGF.read.gsub(
/./,
'>' => 'p+=1;',
'<' => 'p-=1;',
'+' => 'm[p]+=1;',
'-' => 'm[p]-=1;',
'[' => '(',
']' => ')while((m[p]&=255)!=0);',
'.' => 'putc m[p];',
',' => 'm[p]=STDIN.getbyte if !STDIN.eof;')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment