@@ -0,0 +1,1329 @@
+%22%22%22%0ABackward and forward%0A====================%0A%0AThe sign outside reads: Name no one man.%0A%0A%22Escape. We must escape.%22 Staring at the locked door of his cage, %0ABeta Rabbit, spy and brilliant mathematician, has a revelation. %0A%22Of course! Name no one man - it's a palindrome! Palindromes are %0Athe key to opening this lock!%22 %0A%0ATo help Beta Rabbit crack the lock, write a function answer(n) %0Awhich returns the smallest positive integer base b, at least 2, %0Ain which the integer n is a palindrome. The input n will satisfy %0A%220 %3C= n %3C= 1000.%22%0A%0A%0ATest cases%0A==========%0A%0AInputs:%0A    (int) n = 0%0AOutput:%0A    (int) 2%0A%0AInputs:%0A    (int) n = 42%0AOutput:%0A    (int) 4%0A%0A%22%22%22%0A%0A%0Adef recurseBase(array, num, base):%0A    value = num %25 base%0A    if value %3E= 10:%0A        value = chr(value + 87)%0A%0A    array.append(value)%0A    div = num / base%0A    if(div == 0):%0A        return%0A    recurseBase(array, div, base)%0A%0A%0Adef base10toX(num, base):%0A    array = %5B%5D%0A    recurseBase(array, num, base)%0A    return array%5B::-1%5D%0A%0A%0Adef answer(num):%0A%0A    for base in range(2, 30):%0A        base_array = base10toX(num, base)%0A        if base_array == base_array%5B::-1%5D:%0A            return base%0A%0A    return None%0A%0Aif __name__ == %22__main__%22:%0A%0A    for i in range(1001):%0A        base = answer(i)%0A        if base:%0A            print %22Base %25d for number %25d is the first palindrome%22 %25 (base, i)%0A

add base palindrome exercise