cp's OEIS Frontend

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.

A137180 Number of palindromes in the range [1,n] inclusive.

This page as a plain text file.
%I A137180 #21 Jul 24 2024 18:03:13
%S A137180 0,1,2,3,4,5,6,7,8,9,9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
%T A137180 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,
%U A137180 13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15
%N A137180 Number of palindromes in the range [1,n] inclusive.
%D A137180 Clifford A. Pickover, A Passion for Mathematics, Wiley, 2005; see p. 71.
%F A137180 a(n) = A136687(n) - 1.
%t A137180 nthPalindrome[n_] := Block[{q = n + 1 - 10^Floor[ Log10[n + 1 - 10^Floor[ Log10[ n/10]] ]], c = Sum[ Floor[ Floor[ n/(11*10^(k - 1) - 1)]/(Floor[ n/(11*10^(k - 1) - 1)] - 1/10)] - Floor[ Floor[ n/(2*10^k - 1)]/(Floor[ n/(2*10^k - 1)] - 1/10)], {k, Floor[ Log10[ n]] }]}, Mod[q, 10]*11^c*10^Floor[ Log10[ q]] + Sum[ Floor[ Mod[q, 10^(k + 1)]/10^k]*10^(Floor[ Log10[ q]] - k) (10^(2 k + c) + 1) , {k, Floor[ Log10[ q]] }]];
%t A137180 palindromicPi[n_] := Block[{q = Floor[ n*10^-Floor[ Log10[ 10 n]/2]]}, r = q + 10^(Floor[ Log10[ q]] + Mod[ Floor[ Log10[ n]], 2]) - 1; r + Floor[ Tanh[n - nthPalindrome[ r]] ]]; (* after the work of Eric A. Schmidt, see A002113 *)
%t A137180 f[n_] := If[n < 1, 0, palindromicPi@ n]; Array[f, 75, 0] (* _Robert G. Wilson v_, Sep 22 2014 *)
%o A137180 (Python)
%o A137180 def A137180(n):
%o A137180     l = len(s:=str(n))
%o A137180     k = l+1>>1
%o A137180     return n//10**(l-k)-(int(s[k-1::-1])>n%10**k)+10**(k-1+(l&1^1))-1 # _Chai Wah Wu_, Jul 24 2024
%Y A137180 Cf. A002113, A136522, A136687.
%K A137180 nonn,base
%O A137180 0,3
%A A137180 _N. J. A. Sloane_, Apr 21 2008