From: Michael Ulm Date: 2006-08-09T15:12:42+09:00 Subject: Re: Codegolf - Writing a Brainf*ck interpreter Daniel Martin wrote: --snip-- > > I like your use of gsub and wish I could take advantage of that too, > but trying to ends up with a net expansion of my current 214 byte > version: > > c,$k=STDIN.read.split'!' > j=%w[d="\0"*8**5 a=0] > c.each_byte{|i|j<<{?<,"a-=1",?>,"a+=1",?+,"d[a]+=1", > ?-,"d[a]-=1",?[,"while d[a]>0 do",?],"end", > ?.,"print d[a,1]",?,,"d[a]=$k.slice!(0)||exit"}[i]||''} > eval j.join(" > ") > > As with yours, you get to 214 bytes by joining the lines that make up > the hash literal. > 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(" ") -- Michael Ulm R&D Team ISIS Information Systems Austria tel: +43 2236 27551-219, fax: +43 2236 21081 e-mail: michael.ulm@isis-papyrus.com Visit our Website: www.isis-papyrus.com --------------------------------------------------------------- This e-mail is only intended for the recipient and not legally binding. Unauthorised use, publication, reproduction or disclosure of the content of this e-mail is not permitted. This email has been checked for known viruses, but ISIS accepts no responsibility for malicious or inappropriate content. ---------------------------------------------------------------