In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Shorten Brainf*ck Interpreter

Get Adobe Flash player
by Susisu 22 Jul 2010
/**
 * Copyright Susisu ( http://wonderfl.net/user/Susisu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hc1G
 */

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!
        private function b(c:String):String{var a:Vector.<int>=new Vector.<int>(99),r:String="",p:int,t:int,d:Array=c.split(""),l:int=d.length,i:int,j:int;for(;i<l;i++){var n:String=d[i];if(n=="+")a[p]++;if(n=="-")a[p]--;if(n==">")p++;if(n=="<")p--;if(n==".")r+=String.fromCharCode(a[p]);if(n=="["){if(a[p]==0){t=0;for(j=i+1;j<l;j++){if(d[j]=="[")t++;if(d[j]=="]"){if(t>0)t--;else{i=j;break;}}}}}if(n=="]"){if(a[p]!=0){t=0;for(j=i-1;j>=0;j--){if(d[j]=="]")t++;if(d[j]=="["){if(t>0)t--;else{i=j;break;}}}}}}return r;}
    }
}