377 forked from: 397 forked from: Shorten Brainf*ck Interpreter

by bkzen forked from 397 <- forked from: 405 <- 508 forked from: Shorten Brainf*ck Interpreter (diff: 32)
♥0 | Line 14 | Modified 2010-07-26 11:03:15 | MIT License
play

ActionScript3 source code

/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8ZL1
 */

// forked from Susisu's 397 <- forked from: 405 <- 508 forked from: Shorten Brainf*ck Interpreter
// forked from bkzen's 405 <- 508 forked from: Shorten Brainf*ck Interpreter
// forked from Susisu's Shorten Brainf*ck Interpreter
package{
    import flash.display.Sprite;
    import flash.text.TextField;
    [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="60")]
    public class BrainfuckInterpreter extends Sprite{
        public function BrainfuckInterpreter(){
            var code:String="++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
            var result:TextField=new TextField();
            result.text=b(code);
            addChild(result);
        }
        //Please shorten this!
        // 405 char!
        // 397
        // 377
        public function b(c:*):*{with(c){a=new Vector.<int>(9),d=c.split(r=""),l=d.length,i=j=p=t=n=0,e="-+<>.][";for(;i<l;i++){n=1<<e.indexOf(d[i]),a[p]+=(n&3)&&(n|1)-2,p+=(n>>=2)&3&&(n|1)-2,r+=(n>>=2)&1?String.fromCharCode(a[p]):"",t=0;if((n>>=1)&&((n=(n|1)-2)>0?!a[p]:a[p]))for(j=i+n;n>0?j<l:j>=0;j+=n){if(d[j]==(n>0?"[":"]"))t++;if(d[j]==(n>0?"]":"[")&&!t--){i=j;break}}}return r}}
    }
}
        /*どうでもいいことを思いついたのでちょっと短く
        public function b(c:*):*
        {
            with(c)
            {
                a=new Vector.<int>(9),
                d=c.split(r=""),
                l=d.length,i=j=p=t=n=0,
                e="-+<>.][";
                for(;i<l;i++)
                {
                    n=1<<e.indexOf(d[i]),
                    a[p]+=(n&3)&&(n|1)-2,
                    p+=(n>>=2)&3&&(n|1)-2,
                    r+=(n>>=2)&1?String.fromCharCode(a[p]):"",
                    t=0;
                    if((n>>=1)&&((n=(n|1)-2)>0?!a[p]:a[p]))
                    for(j=i+n;n>0?j<l:j>=0;j+=n)
                    {
                        if(d[j]==(n>0?"[":"]"))t++;
                        if(d[j]==(n>0?"]":"[")&&!t--)
                        {
                            i=j;break
                        }
                    }
                }
                return r
            }
        }
         */

Forked