var compute = function(temp, cand, q) {
    var dist = 0.,
        diff;
    for (var i = 0, l = temp.length; i < l; i++) {
	    diff = Math.abs(temp[i] - cand[i]);
	    if (q==1) {
	        dist += diff;
	    } else if (q==2) {
	        dist += diff*diff;
	    } else if (q==Number.POSITIVE_INFINITY) {
	        if (diff > dist) {
	            dist = diff;
	        }
	    } else {
	        dist += Math.pow(diff, q);
		}
    }
    if (q==1 || q==Number.POSITIVE_INFINITY) {
        return dist;
    } else if (q==2) {
        return Math.sqrt(dist);
    } else {
        return Math.pow(dist, 1. / q);
    }
};