Power string by Knuth-Morris-Pratt

    :param x: string
    :returns: largest k such that there is a string y with x = y^k
    :complexity: O(len(x))
764013
def powerstring_by_border(u):
    
    f = maximum_border_length(u)
    n = len(u)
    if n % (n - f[-1]) == 0:       # does the alignment shift divide n ?
        return n // (n - f[-1])    # we found a power decomposition
    return 1
217017
def _quotient_exponent(x, y):
    
    assert mpfr.mpfr_regular_p(x)
    assert mpfr.mpfr_regular_p(y)

    # Make copy of x with the exponent of y.
    x2 = mpfr.Mpfr_t()
    mpfr.mpfr_init2(x2, mpfr.mpfr_get_prec(x))
    mpfr.mpfr_set(x2, x, mpfr.MPFR_RNDN)
    mpfr.mpfr_set_exp(x2, mpfr.mpfr_get_exp(y))

    # Compare x2 and y, disregarding the sign.
    extra = mpfr.mpfr_cmpabs(x2, y) >= 0
    return extra + mpfr.mpfr_get_exp(x) - mpfr.mpfr_get_exp(y)
1264657
def pow2(x: int, p: int) -> int:
    """"""
    while p > 0:
        x = x * x % q
        p -= 1
    return x
354506
def evaluate(self, x):
        ''''''
        # Holds the sum over each term in the polynomial
        #c = 0

        # Holds the current power of x. This is multiplied by x after each term
        # in the polynomial is added up. Initialized to x^0 = 1
        #p = 1

        #for term in self.coefficients[::-1]:
        #    c = c + term * p
        #    p = p * x
        #return c

        # Faster alternative using Horner's Scheme
        y = self[0]
        for i in _range(1, len(self)):
            y = y * x + self.coefficients[i]
        return y
660145
def estimate_complexity(self, x,y,z,n):
        
        num_calculations = x * y * z * n
        run_time = num_calculations / 100000  # a 2014 PC does about 100k calcs in a second (guess based on prior logs)
        return self.show_time_as_short_string(run_time)
304840
def toString(self):
        
        result = []
        k, v = self.optimalRepr()
        longest = reduce(lambda x, y: x if x > len(y) else len(y), k, 0)
        for ind in range(len(k)):
            result.append("%s : %s" % (k[ind].ljust(longest), v[ind]))
        return "\n".join(result)
88160
def _maxlength(X):
    
    return np.fromiter((map(lambda x: len(x), X)), dtype=int).max()
738417
public static int ipowi(int x, int p) {
    if(p <= 2) {
      return (int) FastMath.powFast(x, p);
    }
    int tmp = x, ret = (p & 1) == 1 ? x : 1;
    while(true) {
      tmp *= tmp;
      p >>= 1;
      if(p == 1) {
        return ret * tmp;
      }
      if((p & 1) != 0) {
        ret *= tmp;
      }
    }
  }
324505
def longest_common_substring(s1, s2):
    
    m = [[0] * (1 + len(s2)) for i in range(1 + len(s1))]
    longest, x_longest = 0, 0
    for x in range(1, 1 + len(s1)):
        for y in range(1, 1 + len(s2)):
            if s1[x - 1] == s2[y - 1]:
                m[x][y] = m[x - 1][y - 1] + 1
                if m[x][y] > longest:
                    longest = m[x][y]
                    x_longest = x
            else:
                m[x][y] = 0
    return s1[x_longest - longest: x_longest]
886403
def get_longest_non_repeat_v1(string):
    
    if string is None:
        return 0, ''
    sub_string = ''
    dict = {}
    max_length = 0
    j = 0
    for i in range(len(string)):
        if string[i] in dict:
            j = max(dict[string[i]], j)
        dict[string[i]] = i + 1
        if i - j + 1 > max_length:
            max_length = i - j + 1
            sub_string = string[j: i + 1]
    return max_length, sub_string
1198538
public static int roundUpToPowerOfTwo(int x) {
		x = x - 1;
		x |= x >> 1;
		x |= x >> 2;
		x |= x >> 4;
		x |= x >> 8;
		x |= x >> 16;
		return x + 1;
	}
575871
def string_xor(a, b):
    '''
    '''
    if sys.version_info[0] < 3:
        return ''.join((chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)))
    else:
        return bytes(x ^ y for (x, y) in zip(a, b))
777720
public static String[] unique(String[] x) {
        HashSet<String> hash = new HashSet<>(Arrays.asList(x));

        String[] y = new String[hash.size()];

        Iterator<String> keys = hash.iterator();
        for (int i = 0; i < y.length; i++) {
            y[i] = keys.next();
        }

        return y;
    }
545758
def _full(self, k):
        
        G = np.ones((self.m, self.m))
        #np.fill_diagonal(G, 0) # erroneous code from prefpy
        return G
323801
public SDVariable pow(SDVariable x, SDVariable y) {
        return pow(null, x, y);
    }
1012040
def choose(n, k):
    
    if 0 <= k <= n:
        ntok = 1
        ktok = 1
        for t in xrange(1, min(k, n - k) + 1):
            ntok *= n
            ktok *= t
            n -= 1
        return ntok // ktok
    else:
        return 0
415589
def strxor(s1, s2):
    
    return b"".join(map(lambda x, y: chb(orb(x) ^ orb(y)), s1, s2))