login
A344550
Nested palindromes.
4
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 111, 222, 333, 444, 555, 666, 777, 888, 999, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999, 10101, 11111, 12121, 13131, 14141, 15151, 16161, 17171, 18181, 19191, 20202, 21212, 22222, 23232, 24242
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
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
Sequence in context: A160818 A244514 A082810 * A010785 A343524 A032573
KEYWORD
nonn,base
AUTHOR
James S. DeArmon, May 22 2021
STATUS
approved