Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Check whether an integer is a palindrome for any base and digits length
| ResourceFunction["IntegerPalindromeQ"][n] returns True if the integer n is identical to IntegerReverse[n], 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. | 
A palindromic integer:
| In[1]:= | ![ResourceFunction["IntegerPalindromeQ"][12321]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/3f87c0cafe427c0a.png) | 
| Out[1]= |  | 
A binary palindrome:
| In[2]:= | ![ResourceFunction["IntegerPalindromeQ"][2015, 2]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/09996b6cdff4ad18.png) | 
| Out[2]= |  | 
| In[3]:= | ![BaseForm[2015, 2]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/1effa19a8552a705.png) | 
| Out[3]= |  | 
This is not palindromic:
| In[4]:= | ![ResourceFunction["IntegerPalindromeQ"][1232100]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/12e9929ffbbd6f8a.png) | 
| Out[4]= |  | 
This is a palindrome after padding it with zeros on the left:
| In[5]:= | ![ResourceFunction["IntegerPalindromeQ"][1232100, 10, 9]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/6fc4cb7229b0a46b.png) | 
| Out[5]= |  | 
A palindrome using a mixed radix:
| In[6]:= | ![ResourceFunction["IntegerPalindromeQ"][100, MixedRadix[{7, 11}]]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/6576eda5c44f17be.png) | 
| Out[6]= |  | 
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]:= | ![Select[FromDigits /@ Tuples[{0, 1, 8}, 5], ResourceFunction[
 "IntegerPalindromeQ"]]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/0eed7e6779b9e864.png) | 
| Out[7]= |  | 
Some of them are primes:
| In[8]:= | ![Select[%, PrimeQ]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/208d099581bdfef1.png) | 
| Out[8]= |  | 
For an integer n, IntegerPalindromeQ[n] is equivalent to PalindromeQ[n]:
| In[9]:= | ![ResourceFunction["IntegerPalindromeQ"][12321]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/13353914be79ca25.png) | 
| Out[9]= |  | 
| In[10]:= | ![PalindromeQ[12321]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/1512837835262c15.png) | 
| Out[10]= |  | 
IntegerPalindromeQ[n] is equivalent to IntegerPalindromeQ[n,10]:
| In[11]:= | ![ResourceFunction["IntegerPalindromeQ"][12321]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/245af0e6956a922c.png) | 
| Out[11]= |  | 
| In[12]:= | ![ResourceFunction["IntegerPalindromeQ"][12321, 10]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/0a4559fc4b7cf93a.png) | 
| Out[12]= |  | 
Specify a different base:
| In[13]:= | ![ResourceFunction["IntegerPalindromeQ"][12321, 2]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/50d6d3c61a118b61.png) | 
| Out[13]= |  | 
IntegerPalindromeQ[n,b] is equivalent to IntegerPalindromeQ[n,b,IntegerLength[n,b]]:
| In[14]:= | ![ResourceFunction["IntegerPalindromeQ"][100, 10]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/01784723aa1c9b7b.png) | 
| Out[14]= |  | 
| In[15]:= | ![IntegerLength[100]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/27eff97669e39f8c.png) | 
| Out[15]= |  | 
| In[16]:= | ![ResourceFunction["IntegerPalindromeQ"][100, 10, 3]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/07d0486da269fce6.png) | 
| Out[16]= |  | 
Specify a different digits length:
| In[17]:= | ![ResourceFunction["IntegerPalindromeQ"][100, 10, 5]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/4e09f4f64d12cbf7.png) | 
| Out[17]= |  | 
IntegerPalindromeQ[n,b,len] returns True if n is identical to IntegerReverse[n,b,len]:
| In[18]:= | ![BaseForm[42912, 16]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/0048e314de3a6045.png) | 
| Out[18]= |  | 
| In[19]:= | ![BaseForm[IntegerReverse[42912, 16, 5], 16]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/63abd5fd4d9ed0bc.png) | 
| Out[19]= |  | 
The first nine coefficients of this series expansion are special palindromic numbers:
| In[20]:= | ![Series[-(10 x + 1)/((x - 1) (10 x - 1) (100 x - 1)), {x, 0, 8}]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/4cdae863a46e2134.png) | 
| Out[20]= |  | 
| In[21]:= | ![coeffs = CoefficientList[%, x]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/0ca0265c41bff9b7.png) | 
| Out[21]= |  | 
| In[22]:= | ![ResourceFunction["IntegerPalindromeQ"] /@ coeffs](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/6e65c4796364e0fe.png) | 
| Out[22]= |  | 
Those coefficients can also be generated as squares of repunits 1, 11, 111, etc.:
| In[23]:= | ![coeffs === Table[FromDigits[Table[1, n]]^2, {n, 1, 9}]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/4429dcbeeaf4a0be.png) | 
| Out[23]= |  | 
Addition of an integer n and IntegerReverse[n] gives a palindromic number in some cases:
| In[24]:= | ![With[{n = 253147627}, n + IntegerReverse[n]]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/6aba5c58f8a852e2.png) | 
| Out[24]= |  | 
| In[25]:= | ![ResourceFunction["IntegerPalindromeQ"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/7d5d43b69e7e945f.png) | 
| Out[25]= |  | 
But not always:
| In[26]:= | ![With[{n = 55}, n + IntegerReverse[n]]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/7b0027c7bb9673c7.png) | 
| Out[26]= |  | 
| In[27]:= | ![ResourceFunction["IntegerPalindromeQ"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/6bdf22e7805816a3.png) | 
| Out[27]= |  | 
It is conjectured that this algorithm eventually produces a palindromic number for every decimal input:
| In[28]:= | ![algorithm[n_] := NestWhile[# + IntegerReverse[#] &, n, Not[ResourceFunction["IntegerPalindromeQ"][#]] &]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/66037bbd8ad1e242.png) | 
| In[29]:= | ![algorithm[48]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/506945f1dcc9d044.png) | 
| Out[29]= |  | 
| In[30]:= | ![algorithm[89]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/19c4318d6c4297f8.png) | 
| Out[30]= |  | 
| In[31]:= | ![ResourceFunction["IntegerPalindromeQ"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/6c0e38d265e68972.png) | 
| Out[31]= |  | 
There are numbers for which it is not known whether the algorithm succeeds, the smallest being 196:
| In[32]:= | ![TimeConstrained[algorithm[196], 1]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/0293fde0d37acede.png) | 
| Out[32]= |  | 
An integer can be a palindrome in multiple bases:
| In[33]:= | ![ResourceFunction["IntegerPalindromeQ"][15351, 10]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/2c3a08bddb155fe3.png) | 
| Out[33]= |  | 
| In[34]:= | ![ResourceFunction["IntegerPalindromeQ"][15351, 2]](https://www.wolframcloud.com/obj/resourcesystem/images/20d/20df8fcc-731f-4d6e-bf99-3e5b57aa032e/152de2793796913a.png) | 
| Out[34]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License