
// Miscellaneous functions:

function bench(c,t) {
 s=(new Date()).valueOf();
 for(var i=0;i<t;++i)
  eval(c);
 e=(new Date()).valueOf()-start;
 return e;
};

function range(b,e) {
 var ret = [];
 for(var i = b; i < e; ++i) ret[i] = i; 
 return ret;
};

function xrange(n) { return range(0,n); }

// Number prototyped methods:

Number.prototype.fact=function() {
 var r=1;
 for(var i=this;i>1;--i)
  r*=i;
 return r;
};

Number.prototype.is_prime=function() {
 for(var i=2;i<=Math.sqrt(n=this)<<1>>1;++i)
  if(!(n%i))
   n=0;
 return n>=2;
};

// String prototyped methods:

String.prototype.reverse=function() {
 var s='';
 for(var i=this.length;i>0;--i)
  s+=this[i-1];
 return s;
};

String.prototype.translate=function(a,b) {
 var c=this;
 for(var i in a)
  c=c.replace(a[i],b[i],'g');
 return c;
};

// Array prototyped methods:
/* included in javascript now
Array.prototype.reduce=function(f,s) {
 for(var i in this)
  s=f(s,this[i]);
 return s;
}
*/
// Math functions:

Math.fib=function(n) {
 p=Math.sqrt(5)
 return (Math.pow(1+p,n)-Math.pow(1-p,n))/Math.pow(2,n)*p;
 }

Object.prototype.replicate = function(n) {
 var a = [];
 for(var i = 0; i < n; ++i) { a[i] = this; }
 return a;
}

