Thursday, July 15, 2010

The shortest oneline brainf*ck interpreter in python (558 characters)

Hi, it is Dr. NISHIO Hirokazu. This code was written in 2006-09 but I didn't have publish yet in English.

get from here: http://gist.github.com/476940. It takes a filename as an argument and exec it as Brainf*ck code. All illegal characters are ignored.

exec(reduce(lambda x,y:x.replace(y[0],y[1:]),'Iz"d",|Jz"t",|K1),"|L.read(|Mimport |O,lambda|Psys.std|Q",0);z"|R"Yzp,|S}.get(code[|T)or |U"YZor z"p",p|Vifilter(bool,(|W)%256)or Z,"|X)for x in count())).next()|Y:lambda:|Zz"c",c+1)|q(globals().get(p,0)|zglobals().__setitem__('.split('|'),'Msys;from itertools Mcount,ifilter;z"cQpQj"O kYq==0)^(k==-1)and(Jc+kTI1TVId+{"]":-1,"[":1St],0)*kTd==0 or Jt+kXand z"c",t+1T1TZ);z"code",file(sys.argv[1])L));Vc==len(code)or({">U+K<U-K+Rq+1W-Rq+255W."YPout.write(chrq)TZ,",Rord(PinL1)W[":j(K]":j(-1),Sc]O:Z)()and NoneX'))

See this charm point!

>U+K<U-K+Rq+1W-Rq+255W

It's a definition of >, <, + and - !

No comments: