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.
%I A261423 #39 Feb 16 2025 08:33:26 %S A261423 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, %T A261423 22,22,22,22,22,22,22,33,33,33,33,33,33,33,33,33,33,33,44,44,44,44,44, %U A261423 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 %N A261423 Largest palindrome <= n. %C A261423 Might be called the palindromic floor function. %C A261423 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 %C A261423 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 %H A261423 Reinhard Zumkeller, <a href="/A261423/b261423.txt">Table of n, a(n) for n = 0..10000</a> %H A261423 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/PalindromicNumber.html">Palindromic Number</a> %H A261423 Wikipedia, <a href="http://www.wikipedia.org/wiki/Palindromic_number">Palindromic number</a> %H A261423 <a href="/index/Pac#palindromes">Index entries for sequences related to palindromes</a> %F A261423 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 %p A261423 # P has list of palindromes %p A261423 palfloor:=proc(n) global P; local i; %p A261423 for i from 1 to nops(P) do %p A261423 if P[i]=n then return(n); fi; %p A261423 if P[i]>n then return(P[i-1]); fi; %p A261423 od: %p A261423 end; %t A261423 palQ[n_] := Block[{d = IntegerDigits@ n}, d == Reverse@ d]; Table[k = n; %t A261423 While[Nand[palQ@ k, k > -1], k--]; k, {n, 0, 78}] (* _Michael De Vlieger_, Sep 09 2015 *) %o A261423 (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 %o A261423 (Haskell) %o A261423 a261423 n = a261423_list !! n %o A261423 a261423_list = tail a261914_list -- _Reinhard Zumkeller_, Sep 16 2015 %o A261423 (Python) %o A261423 def P(n): %o A261423 s = str(n); h = s[:(len(s)+1)//2]; return int(h + h[-1-len(s)%2::-1]) %o A261423 def a(n): %o A261423 s = str(n) %o A261423 if s == '1'+'0'*(len(s)-1) and n > 1: return n - 1 %o A261423 Pn = P(n) %o A261423 return Pn if Pn <= n else P(n - 10**(len(s)//2)) %o A261423 print([a(n) for n in range(79)]) # _Michael S. Branicky_, Jun 25 2021 %Y A261423 Cf. A002113, A261424, A261914 (previous palindrome). %Y A261423 Cf. A262038. %Y A261423 Sequences related to palindromic floor and ceiling: A175298, A206913, A206914, A261423, A262038, and the large block of consecutive sequences beginning at A265509. %Y A261423 A262257(n) = Levenshtein distance between n and a(n). - _Reinhard Zumkeller_, Sep 16 2015 %K A261423 nonn,base %O A261423 0,3 %A A261423 _N. J. A. Sloane_, Aug 28 2015