# Is there an efficient way to find minimum xor value between a key and elements of a list?

Assume that I have a list of 10 thousand random numbers chosen in this way: random_num = list(np.random.choice(2**16, 10000, replace=False)) Now, I have a key in the same range (e.g., 1024), and I need to find 10 numbers from the sorted list that have minimum value with the key based on the xor distance: xor_dist… Read More Is there an efficient way to find minimum xor value between a key and elements of a list?

# Python XOR behavior with a mix of positive/negative number

Here is two results I get when I xor 2 integers. The sames bits, but a different sign for the second parameter of the xor. >>> bin(0b0001 ^ -0b0010) ‘-0b1’ >>> bin(0b0001 ^ 0b0010) ‘0b11′ I don’t really understand the logic. Isn’t XOR just supposed so XOR every bit one by one ? Even with… Read More Python XOR behavior with a mix of positive/negative number

# Type mismatch when using map on a zipped list in Scala

Consider this code : /** Takes a list and turns it into an infinite looping stream. */ def loop(l: List[Char]): LazyList[Char] = { l.to(LazyList) #:::loop(l) } /** Encodes a sequence of characters with a looped key. */ def codec(message: Seq[Char], key: Seq[Char], cipher: (Char, Char) => Char): Seq[Char] = { val loopedKey = loop(key.toList) val… Read More Type mismatch when using map on a zipped list in Scala