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.

Showing 1-2 of 2 results.

A262037 Replace the second half of digits of n with the first half in reverse order.

Original entry on oeis.org

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

Views

Author

M. F. Hasler, Sep 08 2015

Keywords

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.

Examples

			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.
		

Crossrefs

Programs

  • 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 *)
  • 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

A262040 Nearest palindrome to n; in case of a tie choose the smaller palindrome.

Original entry on oeis.org

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

Views

Author

M. F. Hasler, Sep 08 2015

Keywords

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).

Examples

			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.
		

Crossrefs

Programs

  • 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 *)
Showing 1-2 of 2 results.