login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A002113 Palindromes in base 10.
(Formerly M0484 N0178)
776

%I M0484 N0178 #323 Sep 08 2022 08:44:29

%S 0,1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,101,111,121,131,141,

%T 151,161,171,181,191,202,212,222,232,242,252,262,272,282,292,303,313,

%U 323,333,343,353,363,373,383,393,404,414,424,434,444,454,464,474,484,494,505,515

%N Palindromes in base 10.

%C n is a palindrome (i.e., a(k) = n for some k) if and only if n = A004086(n). - _Reinhard Zumkeller_, Mar 10 2002

%C A178788(a(n)) = 0 for n > 9. - _Reinhard Zumkeller_, Jun 30 2010

%C A064834(a(n)) = 0. - _Reinhard Zumkeller_, Sep 18 2013

%C It seems that if n*reversal(n) is in the sequence then n = 3 or all digits of n are less than 3. - _Farideh Firoozbakht_, Nov 02 2014

%C The position of a palindrome within the sequence can be determined almost without calculation: If the palindrome has an even number of digits, prepend a 1 to the front half of the palindrome's digits. If the number of digits is odd, prepend the value of front digit + 1 to the digits from position 2 ... central digit. Examples: 98766789 = a(19876), 515 = a(61), 8206028 = a(9206), 9230329 = a(10230). - _Hugo Pfoertner_, Aug 14 2015

%C This sequence is an additive basis of order at most 49, see Banks link. - _Charles R Greathouse IV_, Aug 23 2015

%C The order has been reduced from 49 to 3; see the Cilleruelo-Luca and Cilleruelo-Luca-Baxter links. - _Jonathan Sondow_, Nov 27 2017

%C See A262038 for the "next palindrome" and A261423 for the "preceding palindrome" functions. - _M. F. Hasler_, Sep 09 2015

%C The number of palindromes with d digits is 10 if d = 1, and otherwise it is 9 * 10^(floor((d - 1)/2)). - _N. J. A. Sloane_, Dec 06 2015

%C Sequence A033665 tells how many iterations of the Reverse-then-add function A056964 are needed to reach a palindrome; numbers for which this will never happen are Lychrel numbers (A088753) or rather Kin numbers (A023108). - _M. F. Hasler_, Apr 13 2019

%D Karl G. Kröber, "Palindrome, Perioden und Chaoten: 66 Streifzüge durch die palindromischen Gefilde" (1997, Deutsch-Taschenbücher; Bd. 99) ISBN 3-8171-1522-9.

%D Clifford A. Pickover, A Passion for Mathematics, Wiley, 2005; see p. 71.

%D N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).

%D N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

%H T. D. Noe, <a href="/A002113/b002113.txt">List of first 19999 palindromes: Table of n, a(n) for n = 1..19999</a>

%H Hunki Baek, Sejeong Bang, Dongseok Kim, and Jaeun Lee, <a href="http://arxiv.org/abs/1412.2426">A bijection between aperiodic palindromes and connected circulant graphs</a>, arXiv:1412.2426 [math.CO], 2014.

%H William D. Banks, Derrick N. Hart, and Mayumi Sakata, <a href="http://dx.doi.org/10.4310/MRL.2004.v11.n6.a10">Almost all palindromes are composite</a>, Math. Res. Lett., Vol. 11, No. 5-6 (2004), pp. 853-868.

%H William D. Banks, <a href="http://arxiv.org/abs/1508.04721">Every natural number is the sum of forty-nine palindromes</a>, arXiv:1508.04721 [math.NT], 2015; <a href="https://www.emis.de/journals/INTEGERS/papers/q3/q3.Abstract.html">Integers</a>, 16 (2016), article A3.

%H Javier Cilleruelo, Florian Luca and Lewis Baxter, <a href="https://doi.org/10.1090/mcom/3221">Every positive integer is a sum of three palindromes</a>, Mathematics of Computation, Vol. 87, No. 314 (2018), pp. 3023-3055, <a href="http://arxiv.org/abs/1602.06208">arXiv preprint</a>, arXiv:1602.06208 [math.NT], 2017.

%H Patrick De Geest, <a href="http://www.worldofnumbers.com/">World of Numbers</a>.

%H Phakhinkon Phunphayap and Prapanpong Pongsriiam, <a href="https://arxiv.org/abs/1803.00161">Reciprocal sum of palindromes</a>, arXiv:1803.00161 [math.CA], 2018.

%H Simon Plouffe, <a href="https://arxiv.org/abs/0911.4975">Approximations de séries génératrices et quelques conjectures</a>, Dissertation, Université du Québec à Montréal, 1992; arXiv:0911.4975 [math.NT], 2009.

%H Simon Plouffe, <a href="/A000051/a000051_2.pdf">1031 Generating Functions</a>, Appendix to Thesis, Montreal, 1992

%H Prapanpong Pongsriiam and Kittipong Subwattanachai, <a href="http://ijmcs.future-in-tech.net/14.1/R-Pongsriiam.pdf">Exact Formulas for the Number of Palindromes up to a Given Positive Integer</a>, Intl. J. of Math. Comp. Sci. (2019) 14:1, 27-46.

%H E. A. Schmidt, <a href="https://web.archive.org/web/20110126180310/http://eric-schmidt.com:80/eric/palindrome/index.html">Positive Integer Palindromes</a>. [Cached copy at the Wayback Machine]

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/PalindromicNumber.html">Palindromic Number</a>.

%H Wikipedia, <a href="http://www.wikipedia.org/wiki/Palindromic_number">Palindromic number</a>.

%H <a href="/index/Ab#basis_03">Index entries for sequences that are an additive basis</a>, order 3.

%H <a href="/index/Pac#palindromes">Index entries for sequences related to palindromes</a>

%H <a href="/index/Cor#core">Index entries for "core" sequences</a>

%F A136522(a(n)) = 1.

%F a(n+1) = A262038(a(n)+1). - _M. F. Hasler_, Sep 09 2015

%F Sum_{n>=2} 1/a(n) = A118031. - _Amiram Eldar_, Oct 17 2020

%p read transforms; t0:=[]; for n from 0 to 2000 do if digrev(n) = n then t0:=[op(t0),n]; fi; od: t0;

%p # Alternatively, to get all palindromes with <= N digits in the list "Res":

%p N:=5;

%p Res:= $0..9:

%p for d from 2 to N do

%p if d::even then

%p m:= d/2;

%p Res:= Res, seq(n*10^m + digrev(n),n=10^(m-1)..10^m-1);

%p else

%p m:= (d-1)/2;

%p Res:= Res, seq(seq(n*10^(m+1)+y*10^m+digrev(n),y=0..9),n=10^(m-1)..10^m-1);

%p fi

%p od: Res:=[Res]: # _Robert Israel_, Aug 10 2014

%p # A variant: Gets all base-10 palindromes with exactly d digits, in the list "Res"

%p d:=4:

%p if d=1 then Res:= [$0..9]:

%p elif d::even then

%p m:= d/2:

%p Res:= [seq(n*10^m + digrev(n), n=10^(m-1)..10^m-1)]:

%p else

%p m:= (d-1)/2:

%p Res:= [seq(seq(n*10^(m+1)+y*10^m+digrev(n), y=0..9), n=10^(m-1)..10^m-1)]:

%p fi:

%p Res; # _N. J. A. Sloane_, Oct 18 2015

%p isA002113 := proc(n)

%p simplify(digrev(n) = n) ;

%p end proc: # _R. J. Mathar_, Sep 09 2015

%t palQ[n_Integer, base_Integer] := Module[{idn = IntegerDigits[n, base]}, idn == Reverse[idn]]; (* then to generate any base-b sequence for 1 < b < 37, replace the 10 in the following instruction with b: *) Select[Range[0, 1000], palQ[#, 10] &]

%t base10Pals = {0}; r = 2; Do[Do[AppendTo[base10Pals, n * 10^(IntegerLength[n] - 1) + FromDigits@Rest@Reverse@IntegerDigits[n]], {n, 10^(e - 1), 10^e - 1}]; Do[AppendTo[base10Pals, n * 10^IntegerLength[n] + FromDigits@Reverse@IntegerDigits[n]], {n, 10^(e - 1), 10^e - 1}], {e, r}]; base10Pals (* _Arkadiusz Wesolowski_, May 04 2012 *)

%t nthPalindromeBase[n_, b_] := Block[{q = n + 1 - b^Floor[Log[b, n + 1 - b^Floor[Log[b, n/b]]]], c = Sum[Floor[Floor[n/((b + 1) b^(k - 1) - 1)]/(Floor[n/((b + 1) b^(k - 1) - 1)] - 1/b)] - Floor[Floor[n/(2 b^k - 1)]/(Floor[n/(2 b^k - 1)] - 1/ b)], {k, Floor[Log[b, n]]}]}, Mod[q, b] (b + 1)^c * b^Floor[Log[b, q]] + Sum[Floor[Mod[q, b^(k + 1)]/b^k] b^(Floor[Log[b, q]] - k) (b^(2 k + c) + 1), {k, Floor[Log[b, q]]}]] (* after the work of Eric A. Schmidt, works for all integer bases b > 2 *)

%t Array[nthPalindromeBase[#, 10] &, 61, 0] (* please note that Schmidt uses a different, a more natural and intuitive offset, that of a(1) = 1. - _Robert G. Wilson v_, Sep 22 2014 and modified Nov 28 2014 *)

%t Select[Range[10^3], PalindromeQ] (* _Michael De Vlieger_, Nov 27 2017 *)

%o (PARI) is_A002113(n)=Vecrev(n=digits(n))==n \\ _M. F. Hasler_, Nov 17 2008, updated Apr 26 2014, Jun 19 2018

%o (PARI) is(n)=n=digits(n);for(i=1,#n\2,if(n[i]!=n[#n+1-i],return(0))); 1 \\ _Charles R Greathouse IV_, Jan 04 2013

%o (PARI) a(n)={my(d,i,r);r=vector(#digits(n-10^(#digits(n\11)))+#digits(n\11));n=n-10^(#digits(n\11));d=digits(n);for(i=1,#d,r[i]=d[i];r[#r+1-i]=d[i]);sum(i=1,#r,10^(#r-i)*r[i])} \\ _David A. Corneth_, Jun 06 2014

%o (PARI) \\ recursive--feed an element a(n) and it gives a(n+1)

%o nxt(n)=my(d=digits(n));i=(#d+1)\2;while(i&&d[i]==9,d[i]=0;d[#d+1-i]=0;i--);if(i,d[i]++;d[#d+1-i]=d[i],d=vector(#d+1);d[1]=d[#d]=1);sum(i=1,#d,10^(#d-i)*d[i]) \\ _David A. Corneth_, Jun 06 2014

%o (PARI) \\ feed a(n), returns n.

%o inv(n)={my(d=digits(n));q=ceil(#d/2);sum(i=1,q,10^(q-i)*d[i])+10^floor(#d/2)} \\ _David A. Corneth_, Jun 18 2014

%o (PARI) inv_A002113(P)={P\(P=10^(logint(P+!P,10)\/2))+P} \\ index n of palindrome P = a(n), much faster than above: no sum is needed. - _M. F. Hasler_, Sep 09 2018

%o (PARI) A002113(n,L=logint(n,10))=(n-=L=10^max(L-(n<11*10^(L-1)),0))*L+fromdigits(Vecrev(digits(if(n<L,n,n\10)))) \\ _M. F. Hasler_, Sep 11 2018

%o (Python)# A002113.py # edited by _M. F. Hasler_, Jun 19 2018

%o def A002113_list(nMax):

%o mlist=[]

%o for n in range(nMax+1):

%o mstr=str(n)

%o if mstr==mstr[::-1]:

%o mlist.append(n)

%o return(mlist)

%o (Haskell)

%o a002113 n = a002113_list !! (n-1)

%o a002113_list = filter ((== 1) . a136522) [1..] -- _Reinhard Zumkeller_, Oct 09 2011

%o (Haskell)

%o import Data.List.Ordered (union)

%o a002113_list = union a056524_list a056525_list -- _Reinhard Zumkeller_, Jul 29 2015, Dec 28 2011

%o (Python)

%o from itertools import chain

%o A002113 = sorted(chain(map(lambda x:int(str(x)+str(x)[::-1]),range(1,10**3)),map(lambda x:int(str(x)+str(x)[-2::-1]), range(10**3)))) # _Chai Wah Wu_, Aug 09 2014

%o (Python)

%o from itertools import chain, count

%o A002113 = chain(k for k in count(0) if str(k) == str(k)[::-1])

%o print([next(A002113) for k in range(60)]) # _Jan P. Hartkopf_, Apr 10 2021

%o (Magma) [n: n in [0..600] | Intseq(n, 10) eq Reverse(Intseq(n, 10))]; // _Vincenzo Librandi_, Nov 03 2014

%o (Sage)

%o [n for n in (0..515) if Word(n.digits()).is_palindrome()] # _Peter Luschny_, Sep 13 2018

%o (GAP) Filtered([0..550],n->ListOfDigits(n)=Reversed(ListOfDigits(n))); # _Muniru A Asiru_, Mar 08 2019

%o (Scala) def palQ(n: Int, b: Int = 10): Boolean = n - Integer.parseInt(n.toString.reverse) == 0

%o (0 to 999).filter(palQ(_)) // _Alonso del Arte_, Nov 10 2019

%Y Palindromes in bases 2 through 11: A006995 and A057148, A014190 and A118594, A014192 and A118595, A029952 and A118596, A029953 and A118597, A029954 and A118598, A029803 and A118599, A029955 and A118600, this sequence, A029956. Also A262065 (base 60), A262069 (subsequence).

%Y Palindromic primes: A002385. Palindromic nonprimes: A032350.

%Y Palindromic-pi: A136687.

%Y Cf. A029742 (complement), A086862 (first differences).

%Y Palindromic floor function: A261423, also A261424. Palindromic ceiling: A262038.

%Y Union of A056524 and A056525.

%Y Cf. A004086 (read n backwards), A064834, A118031, A136522 (characteristic function), A178788.

%Y Ways to write n as a sum of three palindromes: A261132, A261422.

%Y Minimal number of palindromes that add to n using greedy algorithm: A088601.

%Y Minimal number of palindromes that add to n: A261675.

%Y Subsequence of A061917 and A221221.

%Y Subsequence: A110745.

%K nonn,base,easy,nice,core

%O 1,3

%A _N. J. A. Sloane_

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 19 15:11 EDT 2024. Contains 371794 sequences. (Running on oeis4.)