OFFSET
1,3
COMMENTS
Both the right and left halves of each term are themselves palindromes.
Here, "half" means ceiling(m/2) digits for an m-digit term, whereas A240601 uses floor(m/2). - Michael S. Branicky, May 22 2021
LINKS
Harvey P. Dale, Table of n, a(n) for n = 1..250
EXAMPLE
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.
MATHEMATICA
Select[Range[0, 10^5], (k=#; f=FromDigits/@(Take[IntegerDigits[k], #]&/@{l=Ceiling[IntegerLength@k/2], -l});
And@@PalindromeQ/@Join[f, {k}])&] (* Giorgos Kalogeropoulos, Jun 24 2021 *)
Select[Range[0, 25000], AllTrue[{#, FromDigits[Take[IntegerDigits[#], Ceiling[ IntegerLength[ #]/2]]]}, PalindromeQ]&] (* Harvey P. Dale, May 15 2022 *)
PROG
(Perl)
foreach $cand (0..200000){
@a=split("", $cand);
$b = join("", reverse @a);
next unless $cand==$b; # palindromes only
$len = int(@a/2.); $lenA = @a;
$len++ unless ($lenA/2 == int $lenA/2); # an even half? or include middle digit
$half = join("", @a[0..($len-1)]);
$revHalf = join("", reverse @a[0..($len-1)]);
next unless $half == $revHalf;
$str .= "$cand, ";
}
chop $str; chop $str; # remove trailing comma and space
print "$str\n"; # write to stdout
(Python)
from itertools import product
def pals(d, base=10): # returns a string
digits = "".join(str(i) for i in range(base))
for p in product(digits, repeat=d//2):
if d//2 > 0 and p[0] == "0": continue
left = "".join(p); right = left[::-1]
for mid in [[""], digits][d%2]:
if left + mid + right != '0': yield left + mid + right
def auptod(dd):
yield 0
for d in range(1, dd+1):
yield from (int(p+p[-1-d%2::-1]) for p in pals((d+1)//2))
print([np for np in auptod(6)]) # Michael S. Branicky, May 22 2021
CROSSREFS
KEYWORD
nonn,base
AUTHOR
James S. DeArmon, May 22 2021
STATUS
approved