From: Daniel Martin Date: 2006-08-10T05:05:38+09:00 Subject: Re: Codegolf - Writing a Brainf*ck interpreter "Simon Strandgaard" writes: > well here is my 141 bytes long version :-) > > eval 'd=[i=0]*8**5'+ARGV[0].gsub(/./){" > "+%w[i+=1 X+=1 i-=1 X-=1 putc(X) X=STDIN.getc end > while(X>0)]['>+<-.,]['.index($&)]}.gsub(/X/,'d[i]') Note that both this and the earlier one you posted don't conform to the interface of the codegolf challenge: namely, that bf program will be presented on stdin, and separated from input by a !. Also, your program fails on this simple bf program: ++++[>++++++++[>++++++++<-]<-]>>[>++++++++++.<-] A correct bf interpreter using the traditional 8-bit cell should output nothing. Yours... doesn't. True, the codegolf people didn't say you had to use an 8-bit cell, so maybe this is ok. However, I hadn't known about putc, and seeing your code gives me some ideas. Note that even with your version, you can save two bytes by NOT doing the .gsub bit, and expanding X into d[a]. Doing that substitution may save you 15 characters out of the %w block, but .gsub(/X/,'d[i]') is seventeen characters long. Anyway, here's where I'm at, at 168 characters: j='d="\0"*8**5;a=0' while i=STDIN.getc j+=' '+%w{1 a-=1 a+=1 while(d[a]>0) end putc(d[a]) d[a]=STDIN.getc||exit d[a]+=1 d[a]-=1}[" <>[].,+-".index(i)||break] end eval j