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.

Original entry on oeis.org

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, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 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
Offset: 0

Views

Author

N. J. A. Sloane, Apr 21 2008

Keywords

References

  • Clifford A. Pickover, A Passion for Mathematics, Wiley, 2005; see p. 71.

Crossrefs

Programs

  • Mathematica
    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]] }]];
    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 *)
    f[n_] := If[n < 1, 0, palindromicPi@ n]; Array[f, 75, 0] (* Robert G. Wilson v, Sep 22 2014 *)
  • Python
    def A137180(n):
        l = len(s:=str(n))
        k = l+1>>1
        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

Formula

a(n) = A136687(n) - 1.