Closed rdebath closed 4 years ago
Right, I'll change that. And yes, I thought that jumps was the easiest and this happened
Now the problem doesn't exist anymore, does it?
Heh, yup that's one way round the problem. Of course you're supposed to run the code too :grin:
#!/usr/bin/ruby
eval 'm=Hash.new(p=0);'+ARGF.read.
gsub(/[^\[\]+,-.<>]/,'').
gsub(/\[\-\]\+*|\++|-+|>+|<+|./, Hash.new{|_, k|
(k[0] == '+') ? "m[p]+="+k.length.to_s+";\n" :
(k[0] == '-') ? "m[p]-="+k.length.to_s+";\n" :
(k[0] == '>') ? "p+="+k.length.to_s+";\n" :
(k[0] == '<') ? "p-="+k.length.to_s+";\n" :
(k[0..3] == '[-]+') ? "m[p]="+(k.length-3).to_s+";\n" : "#{k}\n"
}.merge({
'>' => '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;',
'[-]' => 'm[p]=0;',
'#' => 'print "(p=",p,",m=",m,")\n";'
}));
See: https://esolangs.org/wiki/Newbiefuck
This program detects a "Newbiefuck" interpreter (it says "Hello World!" for BF)
And this is another program that only works with BF