[go: up one dir, main page]

login
Search: a262038 -id:a262038
     Sort: relevance | references | number | modified | created      Format: long | short | data
Palindromes in base 10.
(Formerly M0484 N0178)
+10
800
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, 212, 222, 232, 242, 252, 262, 272, 282, 292, 303, 313, 323, 333, 343, 353, 363, 373, 383, 393, 404, 414, 424, 434, 444, 454, 464, 474, 484, 494, 505, 515
OFFSET
1,3
COMMENTS
n is a palindrome (i.e., a(k) = n for some k) if and only if n = A004086(n). - Reinhard Zumkeller, Mar 10 2002
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
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
This sequence is an additive basis of order at most 49, see Banks link. - Charles R Greathouse IV, Aug 23 2015
The order has been reduced from 49 to 3; see the Cilleruelo-Luca and Cilleruelo-Luca-Baxter links. - Jonathan Sondow, Nov 27 2017
See A262038 for the "next palindrome" and A261423 for the "preceding palindrome" functions. - M. F. Hasler, Sep 09 2015
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
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
REFERENCES
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.
Clifford A. Pickover, A Passion for Mathematics, Wiley, 2005; see p. 71.
N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
LINKS
Hunki Baek, Sejeong Bang, Dongseok Kim, and Jaeun Lee, A bijection between aperiodic palindromes and connected circulant graphs, arXiv:1412.2426 [math.CO], 2014.
William D. Banks, Derrick N. Hart, and Mayumi Sakata, Almost all palindromes are composite, Math. Res. Lett., Vol. 11, No. 5-6 (2004), pp. 853-868.
William D. Banks, Every natural number is the sum of forty-nine palindromes, arXiv:1508.04721 [math.NT], 2015; Integers, 16 (2016), article A3.
Javier Cilleruelo, Florian Luca and Lewis Baxter, Every positive integer is a sum of three palindromes, Mathematics of Computation, Vol. 87, No. 314 (2018), pp. 3023-3055, arXiv preprint, arXiv:1602.06208 [math.NT], 2017.
Patrick De Geest, World of Numbers.
Kritkhajohn Onphaeng, Tammatada Khemaratchatakumthorn, Phakhinkon Napp Phunphayap, and Prapanpong Pongsriiam, Exact Formulas for the Number of Palindromes in Certain Arithmetic Progressions, Journal of Integer Sequences, Vol. 27 (2024), Article 24.4.8. See p. 2.
Phakhinkon Phunphayap and Prapanpong Pongsriiam, Reciprocal sum of palindromes, arXiv:1803.00161 [math.CA], 2018.
Simon Plouffe, Approximations de séries génératrices et quelques conjectures, Dissertation, Université du Québec à Montréal, 1992; arXiv:0911.4975 [math.NT], 2009.
Simon Plouffe, 1031 Generating Functions, Appendix to Thesis, Montreal, 1992
Prapanpong Pongsriiam and Kittipong Subwattanachai, Exact Formulas for the Number of Palindromes up to a Given Positive Integer, Intl. J. of Math. Comp. Sci. (2019) 14:1, 27-46.
E. A. Schmidt, Positive Integer Palindromes. [Cached copy at the Wayback Machine]
Eric Weisstein's World of Mathematics, Palindromic Number.
Wikipedia, Palindromic number.
FORMULA
A136522(a(n)) = 1.
A178788(a(n)) = 0 for n > 9. - Reinhard Zumkeller, Jun 30 2010
A064834(a(n)) = 0. - Reinhard Zumkeller, Sep 18 2013
a(n+1) = A262038(a(n)+1). - M. F. Hasler, Sep 09 2015
Sum_{n>=2} 1/a(n) = A118031. - Amiram Eldar, Oct 17 2020
MAPLE
read transforms; t0:=[]; for n from 0 to 2000 do if digrev(n) = n then t0:=[op(t0), n]; fi; od: t0;
# Alternatively, to get all palindromes with <= N digits in the list "Res":
N:=5;
Res:= $0..9:
for d from 2 to N do
if d::even then
m:= d/2;
Res:= Res, seq(n*10^m + digrev(n), n=10^(m-1)..10^m-1);
else
m:= (d-1)/2;
Res:= Res, seq(seq(n*10^(m+1)+y*10^m+digrev(n), y=0..9), n=10^(m-1)..10^m-1);
fi
od: Res:=[Res]: # Robert Israel, Aug 10 2014
# A variant: Gets all base-10 palindromes with exactly d digits, in the list "Res"
d:=4:
if d=1 then Res:= [$0..9]:
elif d::even then
m:= d/2:
Res:= [seq(n*10^m + digrev(n), n=10^(m-1)..10^m-1)]:
else
m:= (d-1)/2:
Res:= [seq(seq(n*10^(m+1)+y*10^m+digrev(n), y=0..9), n=10^(m-1)..10^m-1)]:
fi:
Res; # N. J. A. Sloane, Oct 18 2015
isA002113 := proc(n)
simplify(digrev(n) = n) ;
end proc: # R. J. Mathar, Sep 09 2015
MATHEMATICA
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] &]
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 *)
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 *)
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 *)
Select[Range[10^3], PalindromeQ] (* Michael De Vlieger, Nov 27 2017 *)
PROG
(PARI) is_A002113(n)=Vecrev(n=digits(n))==n \\ M. F. Hasler, Nov 17 2008, updated Apr 26 2014, Jun 19 2018
(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
(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
(PARI) \\ recursive--feed an element a(n) and it gives a(n+1)
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
(PARI) \\ feed a(n), returns n.
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
(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
(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
(Python) # edited by M. F. Hasler, Jun 19 2018
def A002113_list(nMax):
mlist=[]
for n in range(nMax+1):
mstr=str(n)
if mstr==mstr[::-1]:
mlist.append(n)
return mlist # Bill McEachen, Dec 17 2010
(Python)
from itertools import chain
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
(Python)
from itertools import chain, count
A002113 = chain(k for k in count(0) if str(k) == str(k)[::-1])
print([next(A002113) for k in range(60)]) # Jan P. Hartkopf, Apr 10 2021
(Python) is_A002113 = lambda n: (s:=str(n))[::-1]==s # M. F. Hasler, May 23 2024
(Python)
from math import log10
def A002113(n):
if n < 2: return 0
P = 10**floor(log10(n//2)); M = 11*P
s = str(n - (P if n < M else M-P))
return int(s + s[-2 if n < M else -1::-1]) # M. F. Hasler, Jun 06 2024
(Haskell)
a002113 n = a002113_list !! (n-1)
a002113_list = filter ((== 1) . a136522) [1..] -- Reinhard Zumkeller, Oct 09 2011
(Haskell)
import Data.List.Ordered (union)
a002113_list = union a056524_list a056525_list -- Reinhard Zumkeller, Jul 29 2015, Dec 28 2011
(Magma) [n: n in [0..600] | Intseq(n, 10) eq Reverse(Intseq(n, 10))]; // Vincenzo Librandi, Nov 03 2014
(SageMath)
[n for n in (0..515) if Word(n.digits()).is_palindrome()] # Peter Luschny, Sep 13 2018
(GAP) Filtered([0..550], n->ListOfDigits(n)=Reversed(ListOfDigits(n))); # Muniru A Asiru, Mar 08 2019
(Scala) def palQ(n: Int, b: Int = 10): Boolean = n - Integer.parseInt(n.toString.reverse) == 0
(0 to 999).filter(palQ(_)) // Alonso del Arte, Nov 10 2019
CROSSREFS
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).
Palindromic primes: A002385. Palindromic nonprimes: A032350.
Palindromic-pi: A136687.
Cf. A029742 (complement), A086862 (first differences).
Palindromic floor function: A261423, also A261424. Palindromic ceiling: A262038.
Union of A056524 and A056525.
Cf. A004086 (read n backwards), A064834, A118031, A136522 (characteristic function), A178788.
Ways to write n as a sum of three palindromes: A261132, A261422.
Minimal number of palindromes that add to n using greedy algorithm: A088601.
Minimal number of palindromes that add to n: A261675.
Subsequence of A061917 and A221221.
Subsequence: A110745.
KEYWORD
nonn,base,easy,nice,core
STATUS
approved
Largest palindrome <= n.
+10
87
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 77, 77
OFFSET
0,3
COMMENTS
Might be called the palindromic floor function.
Let P(n) = n with the second half of its digits replaced by the first half of the digits in reverse order. If P(n) <= n, then a(n) = P(n), else if n=10^k then a(n) = n-1, else a(n) = P(n-10^floor(d/2)), where d is the number of digits of n. - M. F. Hasler, Sep 08 2015
The largest differences of n - a(n) occur for n = m*R(2k) - 1, where 1 <= m <= 9 and R(k)=(10^k-1)/9. In this case, n - a(n) = 1.1*10^k - 1. - M. F. Hasler, Sep 05 2018
LINKS
FORMULA
n - a(n) < 1.1*10^floor(d/2), where d = floor(log_10(n)) + 1 is the number of digits of n. - M. F. Hasler, Sep 05 2018
MAPLE
# P has list of palindromes
palfloor:=proc(n) global P; local i;
for i from 1 to nops(P) do
if P[i]=n then return(n); fi;
if P[i]>n then return(P[i-1]); fi;
od:
end;
MATHEMATICA
palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d]; Table[k = n;
While[Nand[palQ@ k, k > -1], k--]; k, {n, 0, 78}] (* Michael De Vlieger, Sep 09 2015 *)
PROG
(PARI) A261423(n, d=digits(n), m=sum(k=1, #d\2, d[k]*10^(k-1)))={if( n%10^(#d\2)<m, n==10^valuation(n, 10)&&return(n-1); d=digits(n-=10^(#d\2) /*#digits may decrease!*/); sum(k=1, #d\2, d[k]*10^(k-1)), m)+n-n%10^(#d\2)} \\ M. F. Hasler, Sep 08 2015, minor edit on Sep 05 2018
(Haskell)
a261423 n = a261423_list !! n
a261423_list = tail a261914_list -- Reinhard Zumkeller, Sep 16 2015
(Python)
def P(n):
s = str(n); h = s[:(len(s)+1)//2]; return int(h + h[-1-len(s)%2::-1])
def a(n):
s = str(n)
if s == '1'+'0'*(len(s)-1) and n > 1: return n - 1
Pn = P(n)
return Pn if Pn <= n else P(n - 10**(len(s)//2))
print([a(n) for n in range(79)]) # Michael S. Branicky, Jun 25 2021
CROSSREFS
Cf. A002113, A261424, A261914 (previous palindrome).
Cf. A262038.
Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
A262257(n) = Levenshtein distance between n and a(n). - Reinhard Zumkeller, Sep 16 2015
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Aug 28 2015
STATUS
approved
Greatest binary palindrome <= n; the binary palindrome floor function.
+10
77
0, 1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 9, 9, 9, 9, 15, 15, 17, 17, 17, 17, 21, 21, 21, 21, 21, 21, 27, 27, 27, 27, 31, 31, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 45, 45, 45, 45, 45, 45, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 63, 63, 65, 65, 65, 65
OFFSET
0,4
COMMENTS
Also the greatest binary palindrome < n + 1;
For n > 0, a(n-1) is the greatest binary palindrome < n.
LINKS
FORMULA
Let n > 2, p = 1 + 2*floor((n-1)/2), m = floor(log_2(p)), q = floor((m+1)/2), s = floor(log_2(p-2^q)),
F(x, r) = floor(x/2^q)*2^q + Sum_{k = 0...q - 1} (floor(x/2^(r-k)) mod 2)*2^k;
If F(p, m) <= n then a(n) = F(p, m), otherwise a(n) = F(p-2^q, s).
By definition: F(p, m) = floor(p/2^q)*2^q + A030101(p) mod 2^q; also: F(p-2^q, s) = floor((p-2^q)/2^q)*2^q + A030101(p-2^q) mod 2^q; [Edited and corrected by Hieronymus Fischer, Sep 08 2018]
a(n) = A006995(A206915(n));
a(n) = A006995(A206915(A206914(n+1))-1);
a(n) = A006995(A206916(A206914(n+1))-1).
EXAMPLE
a(0) = 0 since 0 is the greatest binary palindrome <= 0;
a(1) = 1 since 1 is the greatest binary palindrome <= 1;
a(2) = 1 since 1 is the greatest binary palindrome <= 2;
a(3) = 3 since 3 is the greatest binary palindrome <= 3.
PROG
(Haskell)
a206913 n = last $ takeWhile (<= n) a006995_list
-- Reinhard Zumkeller, Feb 27 2012
CROSSREFS
Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
KEYWORD
nonn,base
AUTHOR
Hieronymus Fischer, Feb 13 2012
STATUS
approved
Smallest number >=n whose binary representation is palindromic and has a 1 whenever the binary representation of n has a 1.
+10
76
0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 15, 15, 15, 15, 15, 15, 17, 17, 27, 27, 21, 21, 31, 31, 27, 27, 27, 27, 31, 31, 31, 31, 33, 33, 51, 51, 45, 45, 63, 63, 45, 45, 63, 63, 45, 45, 63, 63, 51, 51, 51, 51, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 65, 65, 99, 99, 85, 85, 119, 119, 73
OFFSET
0,3
COMMENTS
Old name: "Convert n to binary. OR each respective digit of binary n and binary A030101(n), where A030101(n) is the reversal of the order of the digits in the binary representation of n (given in decimal). a(n) is the decimal value of the result."
By "respective" digits of binary n and binary A030101(n), the rightmost digit of A030101(n) ( which is a 1) is OR'ed with the rightmost digit of n. A030101(n) is represented with the appropriate number of leading 0's.
This is the binary next-palindrome function, the base-2 analog of A262038. - N. J. A. Sloane, Dec 08 2015
LINKS
EXAMPLE
20 in binary is 10100. The reversal of the binary digits is 00101. So, from leftmost to rightmost respective digits, we OR 10100 and 00101: 1 OR 0 = 1. 0 OR 0 = 0. 1 OR 1 = 1. 0 OR 0 = 0. And 0 OR 1 = 1. So, 10100 OR 00101 is 10101, which is 21 in decimal. So a(20) = 21.
MATHEMATICA
Table[f = IntegerDigits[x, 2]; f = f + Reverse[f]; FromDigits[ Table[If[Positive[f[[r]]], 1, 0], {r, 1, Length[f]}], 2], {x, STARTPOINT, ENDPOINT}] (* Dylan Hamilton, Oct 15 2010 *)
f[n_] := Block[{id = IntegerDigits[n, 2]}, FromDigits[ BitOr[ id, Reverse@id], 2]]; Array[f, 72] (* Robert G. Wilson v, Nov 07 2010 *)
CROSSREFS
Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Mar 24 2010
EXTENSIONS
Extended, with redundant initial entries included, by Dylan Hamilton, Oct 15 2010
Edited with new name and offset by N. J. A. Sloane, Dec 08 2015
STATUS
approved
Least binary palindrome >= n; the binary palindrome ceiling function.
+10
75
0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 15, 15, 15, 15, 15, 15, 17, 17, 21, 21, 21, 21, 27, 27, 27, 27, 27, 27, 31, 31, 31, 31, 33, 33, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 51, 51, 51, 51, 51, 51, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 65, 65, 73, 73
OFFSET
0,3
COMMENTS
For n > 0 also the least binary palindrome > n - 1;
a(n+1) is the least binary palindrome > n
LINKS
FORMULA
a(n) = A006995(A206916(n));
a(n) = A006995(A206916(A206913(n-1))+1);
a(n) = A006995(A206915(A206913(n-1))+1);
EXAMPLE
a(0) = 0 since 0 is the least binary palindrome >= 0;
a(1) = 1 since 1 is the least binary palindrome >= 1;
a(2) = 3 since 3 is the least binary palindrome >= 2;
a(5) = 5 since 5 is the least binary palindrome >= 5;
PROG
(Haskell)
a206914 n = head $ dropWhile (< n) a006995_list
-- Reinhard Zumkeller, Feb 27 2012
CROSSREFS
Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
KEYWORD
nonn,base
AUTHOR
Hieronymus Fischer, Feb 15 2012
STATUS
approved
a(n) = largest base-2 palindrome m <= 2n+1 such that every base-2 digit of m is <= the corresponding digit of 2n+1; m is written in base 10.
+10
70
1, 3, 5, 7, 9, 9, 9, 15, 17, 17, 21, 21, 17, 27, 21, 31, 33, 33, 33, 33, 33, 33, 45, 45, 33, 51, 33, 51, 33, 51, 45, 63, 65, 65, 65, 65, 73, 73, 73, 73, 65, 65, 85, 85, 73, 73, 93, 93, 65, 99, 65, 99, 73, 107, 73, 107, 65, 99, 85, 119, 73, 107, 93, 127, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 153
OFFSET
0,2
COMMENTS
A007088(a(n)) = A265510(n). - Reinhard Zumkeller, Dec 11 2015
LINKS
MAPLE
ispal := proc(n) # test for base-b palindrome
local L, Ln, i;
global b;
L := convert(n, base, b);
Ln := nops(L);
for i to floor(1/2*Ln) do
if L[i] <> L[Ln + 1 - i] then return false end if
end do;
return true
end proc
# find max pal <= n and in base-b shadow of n, write in base 10
under10:=proc(n) global b;
local t1, t2, i, m, sw1, L2;
if n mod b = 0 then return(0); fi;
t1:=convert(n, base, b);
for m from n by -1 to 0 do
if ispal(m) then
t2:=convert(m, base, b);
L2:=nops(t2);
sw1:=1;
for i from 1 to L2 do
if t2[i] > t1[i] then sw1:=-1; break; fi;
od:
if sw1=1 then return(m); fi;
fi;
od;
end proc;
b:=2; [seq(under10(2*n+1), n=0..144)]; # Gives A265509
# find max pal <= n and in base-b shadow of n, write in base b
underb:=proc(n) global b;
local t1, t2, i, m, mb, sw1, L2;
if n mod b = 0 then return(0); fi;
t1:=convert(n, base, b);
for m from n by -1 to 0 do
if ispal(m) then
t2:=convert(m, base, b);
L2:=nops(t2);
sw1:=1;
for i from 1 to L2 do
if t2[i] > t1[i] then sw1:=-1; break; fi;
od:
if sw1=1 then mb:=add(t2[i]*10^(i-1), i=1..L2); return(mb); fi;
fi;
od;
end proc;
b:=2; [seq(underb(2*n+1), n=0..144)]; # Gives A265510
MATHEMATICA
A265509 = FromDigits[Min /@ Transpose[{#, Reverse@#}], 2] &@IntegerDigits[2 # + 1, 2] & (* JungHwan Min, Aug 22 2016 *)
PROG
(Haskell)
a265509 n = a265509_list !! n
a265509_list = f (tail a030308_tabf) [[]] where
f (bs:_:bss) pss = y : f bss pss' where
y = foldr (\d v -> 2 * v + d) 0 ys
(ys:_) = dropWhile (\ps -> not $ and $ zipWith (<=) ps bs) pss'
pss' = if bs /= reverse bs then pss else bs : pss
-- Reinhard Zumkeller, Dec 11 2015
CROSSREFS
Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
KEYWORD
nonn,base,look
AUTHOR
N. J. A. Sloane, Dec 09 2015
STATUS
approved
Replace the second half of digits of n with the first half in reverse order.
+10
4
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 77, 77, 77, 77, 77, 77, 77
OFFSET
0,3
COMMENTS
This is related to the "palindromic floor" and "palindromic ceiling" functions A261423 and A262038: a(n) = A261423(n) iff the first half of digits reversed does not exceed the second half of digits (without considering the middle digit in case of an odd number of digits), and a(n) = A262038(n) in the opposite case, i.e., first half of digits reversed is greater than or equal to second half of digits.
a(n) is either equal to the palindromic floor A261423(n) (e.g., a(1234) = 1221), or to the palindromic ceiling A262038(n) (= next larger palindrome, e.g., a(1324)=1331). In this sense it can be seen as a "palindromic round" function. However, it does not always yield the closest of the two (a(1900) = 1991 but 1881 would be closer to 1900). The sequence A262040 which has this property would better merit the name of "palindromic round function".
This simple function can be used to construct the next larger or next smaller palindrome, A261423 and A262038: indeed, if a(n) has the required property (less than or greater than n) then it is already the desired result, otherwise the result is given by a(n +- 10^k), where k is half the number of digits of n.
EXAMPLE
a(31) = 33 since the second half ("1") gets replaced by the first half ("3").
a(314) = 313 since the second half ("4") is replaced by the first half ("3"), the middle "1" being untouched.
a(3141) = 3113 since the second half (41) is replaced by the first half (31), reversed (13).
a(31415) = 31413 as above, the middle 4 being left untouched.
a(314156) = 314413. This is the first instance in these examples where a(n) differs from A261423(n), which would yield 313313 here.
MATHEMATICA
f[n_] := Block[{d = IntegerDigits@ n}, FromDigits[Take[d, Ceiling[Length[d]/2]]~Join~Reverse@ Take[d, Floor[Length[d]/2]]]]; Table[f@ n, {n, 0, 120}] (* Michael De Vlieger, Sep 09 2015 *)
PROG
(PARI) a(n, d=digits(n), m=sum(k=1, #d\2, d[k]*10^(k-1)))=n+m-n%10^(#d\2)
(Python)
def A262037(n):
s = str(n); h = s[:(len(s)+1)//2]; return int(h + h[-1-len(s)%2::-1])
print([A262037(n) for n in range(77)]) # Michael S. Branicky, Sep 15 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
M. F. Hasler, Sep 08 2015
STATUS
approved
Nearest palindrome to n; in case of a tie choose the larger palindrome.
+10
2
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 11, 11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 77, 77
OFFSET
0,3
COMMENTS
In analogy to the numerical "round" function, we "round up" to the next larger palindrome A262038(n) if it is at the same distance or closer, else we "round down" to the next smaller palindrome A261423(n). See A262040 for a variant where the next smaller palindrome is chosen in case of equal distance.
EXAMPLE
a(10) = 11 since we round up if the next smaller palindrome (here 9) is at the same distance, both 9 and 11 are here at distance 1 from n = 10.
a(16) = 11 since |16 - 11| = 5 is smaller than |16 - 22| = 6.
a(17) = 22 since |17 - 22| = 5 is smaller than |17 - 11| = 6.
a(27) = 22 since |22 - 27| = 5 is smaller than |27 - 33| = 6.
a(28) = 33 since |33 - 28| = 5 is smaller than |22 - 28| = 6, and so on.
a(100) = 101 because we round up again in this case, where 99 and 101 both are at distance 1 from n = 100.
MATHEMATICA
palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d];
f[n_] := Block[{k = n}, While[Nand[palQ@ k, k > -1], k--]; k];
g[n_] := Block[{k = n}, While[! palQ@ k, k++]; k];
h[n_] := Block[{a = f@ n, b = g@ n}, Which[palQ@ n, n, (b - n) - (n - a) > 0, a, (b - n) - (n - a) <= 0, b]]; Table[h@ n, {n, 0, 73}] (* Michael De Vlieger, Sep 09 2015 *)
CROSSREFS
KEYWORD
nonn,base
AUTHOR
M. F. Hasler, Sep 08 2015
STATUS
approved
Nearest palindrome to n; in case of a tie choose the smaller palindrome.
+10
2
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 11, 11, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 77, 77
OFFSET
0,3
COMMENTS
In contrast to A262039, here we "round down" to the next smaller palindrome A261423(n) if it is at the same distance or closer, else we "round up" to the next larger palindrome A262038(n).
EXAMPLE
a(10) = 9 since we round down if the next larger palindrome (here 11) is at the same distance, both 9 and 11 are here at distance 1 from n = 10.
a(16) = 11 since |16 - 11| = 5 is smaller than |16 - 22| = 6.
a(17) = 22 since |17 - 22| = 5 is smaller than |17 - 11| = 6.
a(27) = 22 since |22 - 27| = 5 is smaller than |27 - 33| = 6.
a(28) = 33 since |33 - 28| = 5 is smaller than |22 - 28| = 6, and so on.
a(100) = 99 because we round down in this case, where 99 and 101 both are at distance 1 from n = 100.
MATHEMATICA
palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d];
f[n_] := Block[{k = n}, While[Nand[palQ@ k, k > -1], k--]; k];
g[n_] := Block[{k = n}, While[! palQ@ k, k++]; k];
h[n_] := Block[{a = f@ n, b = g@ n}, Which[palQ@ n, n, (b - n) - (n - a) >= 0, a, (b - n) - (n - a) < 0, b]]; Table[h@ n, {n, 0, 73}] (* Michael De Vlieger, Sep 09 2015 *)
CROSSREFS
KEYWORD
nonn,base
AUTHOR
M. F. Hasler, Sep 08 2015
STATUS
approved
a(n) = largest base-2 palindrome m <= 2n+1 such that every base-2 digit of m is <= the corresponding digit of 2n+1; m is written in base 2.
+10
2
1, 11, 101, 111, 1001, 1001, 1001, 1111, 10001, 10001, 10101, 10101, 10001, 11011, 10101, 11111, 100001, 100001, 100001, 100001, 100001, 100001, 101101, 101101, 100001, 110011, 100001, 110011, 100001, 110011, 101101, 111111, 1000001, 1000001, 1000001, 1000001, 1001001, 1001001, 1001001, 1001001, 1000001, 1000001
OFFSET
0,2
COMMENTS
a(n) = A007088(A265509(n)). - Reinhard Zumkeller, Dec 11 2015
LINKS
PROG
(Haskell)
a265510 = a007088 . a265509 -- Reinhard Zumkeller, Dec 11 2015
CROSSREFS
Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509.
Cf. A007088.
KEYWORD
nonn,base
AUTHOR
N. J. A. Sloane, Dec 09 2015
STATUS
approved

Search completed in 0.024 seconds