Beispiel #1
0
 def singleNumber(self, nums):
     """
     :type nums: List[int]
     :rtype: int
     """
     ans = 0
     for n in nums:
         ans = xor(ans, n)
     return ans
Beispiel #2
0
 def singleNumber(self, nums):
     """
     :type nums: List[int]
     :rtype: int
     """
     ans = 0
     for n in nums:
         ans = xor(ans, n)
     return ans;
Beispiel #3
0
    def interp_heading(self):
        """Interpolate invalid headings. Use linear interpolation if there are
        valid values on either side of the invalid heading. If the invalid heading
        occurs at the beginning of the time series, back fill using the 1st valid.
        If the invalid heading occurs at the end of the time series, forward fill
        with the last valid self.data.
        """

        idx_invalid = np.where(np.isnan(self.data))[0]

        if len(idx_invalid) > 0:

            first_valid_idx = np.where(np.isnan(self.data) == False)[0][0]
            last_valid_idx = np.where(np.isnan(self.data) == False)[0][-1]

            # Process each invalid self.data
            for n in range(len(idx_invalid)):
                before_idx = np.where(
                    np.isnan(self.data[0:idx_invalid[n] + 1]) == False)[0]
                after_idx = np.where(
                    np.isnan(self.data[idx_invalid[n]:]) == False)[0]

                # If invalid self.data is beginning back fill
                if len(before_idx) < 1:
                    self.data[idx_invalid[n]] = self.data[first_valid_idx]

                # If invalid self.data is at end forward fill
                elif len(after_idx) < 1:
                    self.data[idx_invalid[n]] = self.data[last_valid_idx]

                # If invalid self.data is in middle interpolate
                else:
                    before_idx = before_idx[-1]
                    after_idx = after_idx[0] + idx_invalid[n]

                    test1 = self.data[before_idx] > 180
                    test2 = self.data[after_idx] > 180
                    c = None
                    if not xor(test1, test2):
                        c = 0
                    elif test1:
                        c = 360
                    elif test2:
                        c = -360
                    self.data[idx_invalid[n]] = (
                        ((self.data[after_idx] - self.data[before_idx] + c) /
                         (before_idx - after_idx)) *
                        (before_idx - idx_invalid[n])) + self.data[before_idx]
                    if self.data[idx_invalid[n]] > 360:
                        self.data[
                            idx_invalid[n]] = self.data[idx_invalid[n]] - 360
                    elif self.data[idx_invalid[n]] < 0:
                        self.data[
                            idx_invalid[n]] = self.data[idx_invalid[n]] + 360
Beispiel #4
0
def tent(x, j, k):
    word = ""

    cont = 0

    for c in cipher:

        x = cont % 3

        if x == 0:

            word += chr(xor(c, x))

        elif x == 1:

            word += chr(xor(c, j))

        else:

            word += chr(xor(c, k))
        cont += 1

    return word
 def simpleHash(self, source, seed):
     return xor((source >> mod(seed, 64)), seed)
Beispiel #6
0
 def simpleHash(self, source, seed):
     return xor((source >> mod(seed, 64)), seed)
Beispiel #7
0
 def singleNumber(self, ns):
     one, two = 0, 0
     for n in ns:
         one = (xor(one, n) & (~two))
         two = (xor(two, n) & (~one))
     return one