Function Repository Resource:

# IntegerPalindromeQ

Check whether an integer is a palindrome for any base and digits length

Contributed by: Ian Ford (Wolfram Research)
 ResourceFunction["IntegerPalindromeQ"][n] returns True if the integer n is identical to , and False otherwise. ResourceFunction["IntegerPalindromeQ"][n,b] returns True if the integer n is identical to IntegerReverse[n,b], and False otherwise. ResourceFunction["IntegerPalindromeQ"][n,b,len] returns True if the integer n is identical to IntegerReverse[n,b,len], and False otherwise.

## Details

ResourceFunction["IntegerPalindromeQ"][n] is equivalent to ResourceFunction["IntegerPalindromeQ"][n,10].
ResourceFunction["IntegerPalindromeQ"][n,b] is equivalent to ResourceFunction["IntegerPalindromeQ"][n,b,IntegerLength[n,b]].
ResourceFunction["IntegerPalindromeQ"][0,b,len] returns True for any base b and digits length len.

## Examples

### Basic Examples (3)

A palindromic integer:

 In[1]:=
 Out[1]=

A binary palindrome:

 In[2]:=
 Out[2]=
 In[3]:=
 Out[3]=

This is not palindromic:

 In[4]:=
 Out[4]=

This is a palindrome after padding it with zeros on the left:

 In[5]:=
 Out[5]=

### Scope (1)

A palindrome using a mixed radix:

 In[6]:=
 Out[6]=

### Applications (2)

Tetradic numbers remain invariant when flipped back to front and up-down. Hence they only contain digits 0, 1, 8. These are all tetradic numbers with up to five digits:

 In[7]:=
 Out[7]=

Some of them are primes:

 In[8]:=
 Out[8]=

### Properties and Relations (6)

For an integer n, IntegerPalindromeQ[n] is equivalent to PalindromeQ[n]:

 In[9]:=
 Out[9]=
 In[10]:=
 Out[10]=

IntegerPalindromeQ[n] is equivalent to IntegerPalindromeQ[n,10]:

 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=

Specify a different base:

 In[13]:=
 Out[13]=

IntegerPalindromeQ[n,b] is equivalent to IntegerPalindromeQ[n,b,IntegerLength[n,b]]:

 In[14]:=
 Out[14]=
 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

Specify a different digits length:

 In[17]:=
 Out[17]=

IntegerPalindromeQ[n,b,len] returns True if n is identical to IntegerReverse[n,b,len]:

 In[18]:=
 Out[18]=
 In[19]:=
 Out[19]=

The first nine coefficients of this series expansion are special palindromic numbers:

 In[20]:=
 Out[20]=
 In[21]:=
 Out[21]=
 In[22]:=
 Out[22]=

Those coefficients can also be generated as squares of repunits 1, 11, 111, etc.:

 In[23]:=
 Out[23]=

Addition of an integer n and gives a palindromic number in some cases:

 In[24]:=
 Out[24]=
 In[25]:=
 Out[25]=

But not always:

 In[26]:=
 Out[26]=
 In[27]:=
 Out[27]=

It is conjectured that this algorithm eventually produces a palindromic number for every decimal input:

 In[28]:=
 In[29]:=
 Out[29]=
 In[30]:=
 Out[30]=
 In[31]:=
 Out[31]=

There are numbers for which it is not known whether the algorithm succeeds, the smallest being 196:

 In[32]:=
 Out[32]=

### Neat Examples (1)

An integer can be a palindrome in multiple bases:

 In[33]:=
 Out[33]=
 In[34]:=
 Out[34]=

## Version History

• 1.0.0 – 17 October 2022