Palindromic List

One beautiful property of XOR (symbol : \oplus ) is that for any integer x x , we have x x = 0 x \oplus x = 0 . Using this property, Chris came up with an algorithm that check if a list L L is palindromic.

1
2
3
4
5
6
7
8
9
def is_pal(L):
    val = 0
    for i in range(len(L)):
        val += L[i] ^ L[-i-1]

    if val == 0:
        return True
    else:
        return False

Certainly, this function is restricted to lists that contain only numbers. What is the domain of the numbers in the list such that this function is applicable without error?

Details and Assumptions

  • a ^ b returns a b a\oplus b .
  • A list L is palindromic if L remains the same after applying L.reverse() .
  • In Python's list, the last element is L[-1] , second last element is L[-2] and so on.
Negative real numbers Positive real numbers Integers Non-negative integers Non-negative real numbers Positive integers Real numbers Negative integers

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

0 solutions

No explanations have been posted yet. Check back later!

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...