[go: up one dir, main page]

login
A029967 revision #22

A029967
Palindromic in bases 12 and 10.
40
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 181, 555, 616, 676, 737, 797, 1111, 8008, 35953, 43934, 88888, 646646, 3192913, 5641465, 8364638, 9963699, 133373331, 139979931, 293373392, 520020025, 713171317, 796212697, 1393223931
OFFSET
1,3
MATHEMATICA
NextPalindrome[n_] := Block[{l = Floor[ Log[10, n] + 1], idn = IntegerDigits[n]}, If[ Union[idn] == {9}, Return[n + 2], If[l < 2, Return[n + 1], If[ FromDigits[ Reverse[ Take[idn, Ceiling[l/2]] ]] FromDigits[ Take[idn, -Ceiling[l/2]]], FromDigits[ Join[ Take[idn, Ceiling[l/2]], Reverse[ Take[idn, Floor[l/2]] ]]], idfhn = FromDigits[ Take[idn, Ceiling[l/2]]] + 1; idp = FromDigits[ Join[ IntegerDigits[idfhn], Drop[ Reverse[ IntegerDigits[idfhn]], Mod[l, 2]] ]]] ]]]; palQ[n_Integer, base_Integer] := Block[{idn = IntegerDigits[n, base]}, idn == Reverse[idn]]; l = {0}; a = 0; Do[a = NextPalindrome[a]; If[ palQ[a, 12], AppendTo[l, a]], {n, 400000}]; l (* Robert G. Wilson v, Sep 30 2004 *)
Select[Range[0, 10^5],
PalindromeQ[#] && # == IntegerReverse[#, 12] &] (* Robert Price, Nov 09 2019 *)
PROG
(Python)
from gmpy2 import digits
def palQ(n, b): # check if n is a palindrome in base b
....s = digits(n, b)
....return s == s[::-1]
def palQgen10(l): # generator of palindromes in base 10 of length <= 2*l
....if l > 0:
........yield 0
........for x in range(1, l+1):
............for y in range(10**(x-1), 10**x):
................s = str(y)
................yield int(s+s[-2::-1])
............for y in range(10**(x-1), 10**x):
................s = str(y)
................yield int(s+s[::-1])
A029967_list = [n for n in palQgen10(5) if palQ(n, 12)] # Chai Wah Wu, Dec 01 2014
KEYWORD
nonn,base
STATUS
reviewed