Sansa and XOR

  • + 0 comments

    XOR for array with even number of elements is always 0

    def sansaXor(arr):

    arr_len = len(arr)
    if arr_len % 2 == 0:
        return 0
    c = 0
    for i in range(arr_len):
        if i % 2 == 0:
            c ^= arr[i]
    return c