Shorten Brainf*ck Interpreter
♥2 |
Line 14 |
Modified 2010-07-22 17:56:53 |
MIT License
archived:2017-03-09 10:54:34
ActionScript3 source code
/**
* 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;}
}
}