cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A344550 Nested palindromes.

This page as a plain text file.
%I A344550 #58 May 15 2022 19:25:01
%S A344550 0,1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,111,222,333,444,555,
%T A344550 666,777,888,999,1111,2222,3333,4444,5555,6666,7777,8888,9999,10101,
%U A344550 11111,12121,13131,14141,15151,16161,17171,18181,19191,20202,21212,22222,23232,24242
%N A344550 Nested palindromes.
%C A344550 Both the right and left halves of each term are themselves palindromes.
%C A344550 Here, "half" means ceiling(m/2) digits for an m-digit term, whereas A240601 uses floor(m/2). - _Michael S. Branicky_, May 22 2021
%H A344550 Harvey P. Dale, <a href="/A344550/b344550.txt">Table of n, a(n) for n = 1..250</a>
%e A344550 2222 is a nested palindrome since 22=22, and taking just one side, 2=2. For an example using an odd number of digits, 68686 is a nested palindrome since 686 is a palindrome. Using parentheses to indicate nesting: ( (22) (22) ) and ( (686) (686) ), where, in the second example, the middle-most 6 is repeated for exposition.
%t A344550 Select[Range[0,10^5],(k=#;f=FromDigits/@(Take[IntegerDigits[k],#]&/@{l=Ceiling[IntegerLength@k/2],-l});
%t A344550 And@@PalindromeQ/@Join[f,{k}])&] (* _Giorgos Kalogeropoulos_, Jun 24 2021 *)
%t A344550 Select[Range[0,25000],AllTrue[{#,FromDigits[Take[IntegerDigits[#],Ceiling[ IntegerLength[ #]/2]]]},PalindromeQ]&] (* _Harvey P. Dale_, May 15 2022 *)
%o A344550 (Perl)
%o A344550 foreach $cand (0..200000){
%o A344550     @a=split("",$cand);
%o A344550     $b = join("",reverse @a);
%o A344550     next unless $cand==$b; # palindromes only
%o A344550     $len = int(@a/2.); $lenA = @a;
%o A344550     $len++ unless ($lenA/2 == int $lenA/2); # an even half? or include middle digit
%o A344550     $half = join("",@a[0..($len-1)]);
%o A344550     $revHalf = join("",reverse @a[0..($len-1)]);
%o A344550     next unless $half == $revHalf;
%o A344550     $str .= "$cand, ";
%o A344550 }
%o A344550 chop $str;  chop $str;  # remove trailing comma and space
%o A344550 print "$str\n";  # write to stdout
%o A344550 (Python)
%o A344550 from itertools import product
%o A344550 def pals(d, base=10): # returns a string
%o A344550   digits = "".join(str(i) for i in range(base))
%o A344550   for p in product(digits, repeat=d//2):
%o A344550     if d//2 > 0 and p[0] == "0": continue
%o A344550     left = "".join(p); right = left[::-1]
%o A344550     for mid in [[""], digits][d%2]:
%o A344550         if left + mid + right != '0': yield left + mid + right
%o A344550 def auptod(dd):
%o A344550   yield 0
%o A344550   for d in range(1, dd+1):
%o A344550     yield from (int(p+p[-1-d%2::-1]) for p in pals((d+1)//2))
%o A344550 print([np for np in auptod(6)]) # _Michael S. Branicky_, May 22 2021
%Y A344550 Cf. A002113, A240601.
%K A344550 nonn,base
%O A344550 1,3
%A A344550 _James S. DeArmon_, May 22 2021