Given a number \$n\$, write a program that finds the smallest base \$b ≥ 2\$ such that \$n\$ is a palindrome in base \$b\$. For example, an input of \$28\$ should return the base \$3\$ since \$28_{10} = 1001_3\$. Although \$93\$ is a palindrome in both base \$2\$ and base \$5\$, the output should be \$2\$ since \$2<5\$.
Input
A positive integer \$n < 2^{31}\$.
Output
Return the smallest base \$b ≥ 2\$ such that the base \$b\$ representation of \$n\$ is a palindrome. Do not assume any leading zeros.
Samples (input => output):
\$11 \to 10\$
\$32 \to 7\$
\$59 \to 4\$
\$111 \to 6\$
Rules
The shortest code wins.
n
can be 1 and 2 is not a base 1 palindrome. However, every positiven
is a basen + 1
palindrome. \$\endgroup\$