static function factorial(n:Int):Int { var result = 1; while (1