Finds d, r s.t. n-1 = 2^r * d
555717
def find_spelling(n):
    
    r = 0
    d = n - 1
    # divmod used for large numbers
    quotient, remainder = divmod(d, 2)
    # while we can still divide 2's into n-1...
    while remainder != 1:
        r += 1
        d = quotient  # previous quotient before we overwrite it
        quotient, remainder = divmod(d, 2)
    return r, d
858082
private int rational(int n) {
		while (n >= shapes.size()) {
			n -= shapes.size();
		}
		while (n < 0) {
			n += shapes.size();
		}
		
		return n;
	}
582863
def _rotate(n, x, y, rx, ry):
    
    if ry == 0:
        if rx == 1:
            x = n - 1 - x
            y = n - 1 - y
        return y, x
    return x, y
1152188
def dms2dd(d,m,s):
    
    if d < 0:
        sign = -1
    else:
        sign = 1
    dd = sign * (int(abs(d)) + float(m) / 60 + float(s) / 3600)
    return dd
1346177
private static double getSideLengthFromInscribedRadius(double radius, int n) {
		if (n == 2) {
			return radius;
		}
		return radius * 2 * Math.tan(Math.PI/n);
	}
1118051
def dInd_calc(TNR, TPR):
    
    try:
        result = math.sqrt(((1 - TNR)**2) + ((1 - TPR)**2))
        return result
    except Exception:
        return "None"
443937
def dd2dms(dd):
    
    n = dd < 0
    dd = abs(dd)
    m,s = divmod(dd*3600,60)
    d,m = divmod(m,60)
    if n:
        d = -d
    return d,m,s
47410
def factor_kkt(U_S, R, d):
    
    nineq = R.size(0)
    U_S[-nineq:, -nineq:] = torch.potrf(R + torch.diag(1 / d.cpu()).type_as(d))
922909
def zmeshgrid(d):
    
    lin = xfun(2, d)
    one = ones(2, d)

    xx = zkronv(lin, one)
    yy = zkronv(one, lin)

    return xx, yy
830531
def next_power_of_2(x):
    

    power_of_2 = 1 if x == 0 else 2 ** np.ceil(np.log2(x))
    return power_of_2
858168
public static int solveQuad (double[] eqn, double[] res) {
        double a = eqn[2];
        double b = eqn[1];
        double c = eqn[0];
        int rc = 0;
        if (a == 0f) {
            if (b == 0f) {
                return -1;
            }
            res[rc++] = -c / b;
        } else {
            double d = b * b - 4f * a * c;
            // d < 0f
            if (d < 0f) {
                return 0;
            }
            d = Math.sqrt(d);
            res[rc++] = (-b + d) / (a * 2f);
            // d != 0f
            if (d != 0f) {
                res[rc++] = (-b - d) / (a * 2f);
            }
        }
        return fixRoots(res, rc);
    }
850598
private static final void divmod(byte[] q, byte[] r, int n, byte[] d, int t) {
		int rn = 0;
		int dt = ((d[t-1] & 0xFF) << 8);
		if (t>1) {
			dt |= (d[t-2] & 0xFF);
		}
		while (n-- >= t) {
			int z = (rn << 16) | ((r[n] & 0xFF) << 8);
			if (n>0) {
				z |= (r[n-1] & 0xFF);
			}
			z/=dt;
			rn += mula_small(r,r, n-t+1, d, t, -z);
			q[n-t+1] = (byte)((z + rn) & 0xFF); /* rn is 0 or -1 (underflow) */
			mula_small(r,r, n-t+1, d, t, -rn);
			rn = (r[n] & 0xFF);
			r[n] = 0;
		}
		r[t-1] = (byte)rn;
	}
1165863
def dlmk(l,m,k,theta1):
    
    
    if m >= k:
        
        factor = sqrt(factorial(l-k)*factorial(l+m)/factorial(l+k)/factorial(l-m))
        part2 = (cos(theta1/2))**(2*l+k-m)*(-sin(theta1/2))**(m-k)/factorial(m-k)
        part3 = sp.hyp2f1(m-l,-k-l,m-k+1,-(tan(theta1/2))**2)

        return factor*part2*part3
    
    else:
        
        return (-1)**(m-k) * dlmk(l,k,m,theta1)
155889
def Incr(self, x, term=1):
        
        self.d[x] = self.d.get(x, 0) + term
1202093
private double rdist(double[] x1, double[] x2) {
        double d = 0.0;
        for (int i = 0; i < x1.length; i++) {
            double t = x1[i] - x2[i];
            d += t * t;
        }
        return Math.sqrt(d);
    }
953618
def factorial(n):
    
    f = 1
    while (n > 0):
        f = f * n
        n = n - 1
    return f
781628
def psq2(d1, d2):
    
    d1, d2 = flatten(d1), flatten(d2)

    def f(p):
        return sum((p ** 2) * np.nan_to_num(np.log(p * len(p))))

    return abs(f(d1) - f(d2))