From: Daniel Martin Date: 2006-08-09T22:39:13+09:00 Subject: Re: Codegolf - Writing a Brainf*ck interpreter Michael Ulm writes: > Very nice. If you accept a more fragile version (but still conforming > to the specs) you can bring that down to 210 bytes: > > c,$k=STDIN.read.split'!' > j=%w[d="\0"*8**5 a=0] > c.each_byte{|i|j<<({10,"",?<,"a-=1",?>,"a+=1", > ?[,"while d[a]>0 do",?],"end",?.,"print d[a,1]", > ?,,"d[a]=$k.slice!(0)||exit"}[i]||"d[a]+=#{44-i}")} > eval j.join(" > ") I managed to squeeze out a few more characters by replacing the hash lookup with an array index. I also switched out slice!(0) for an indexing operation, but in the end that caused no overall character count change. Anyway, here's 198 characters: c,$k=STDIN.read.split'!' j=%w[d="\0"*8**5 q=a=0] c.each_byte{|i|j<<' a-=1 a+=1 while d[a]>0 end print d[a,1] d[a]=$k[q]||exit;q+=1 d[a]+=1 d[a]-=1'.split(' ')[" <>[].,+-".index(i)]} eval j.join(" ") As an added bonus (?), all the newlines in that are necessary to the code. Still, there's supposedly another way to squeeze an additional 50 characters out, which I think is going to require some sort of fundamental shift in the approach to the problem.