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.

A353157 a(n) is the distance from n to the nearest integer whose binary expansion has no common 1-bits with that of n.

Original entry on oeis.org

0, 1, 1, 1, 1, 3, 2, 1, 1, 3, 5, 5, 4, 3, 2, 1, 1, 3, 5, 7, 9, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25
Offset: 0

Views

Author

Rémy Sigrist, Apr 27 2022

Keywords

Comments

Equivalently the distance to the nearest integer that can be added without carries in base 2.

Examples

			For n = 42 ("101010" in binary):
- 21 ("10101") is the greatest number <= 42 that has no common 1-bits with 42,
- 128 ("1000000") is the least number >= 42 that has no common 1-bits with 42,
- so a(42) = min(42-21, 128-42) = min(21, 86) = 21.
		

Crossrefs

Programs

  • PARI
    a(n) = { my (high=2^#binary(n), low=high-1-n); min(n-low, high-n) }

Formula

a(n) = min(A006257(n), A080079(n)) for any n > 0.
a(n) = 1 iff n belongs to A097110.
a(n) = n/2 iff n belongs to A020988.
a(n) = n/4 iff n belongs to A108019.
2*a(n) - a(2*n) = 0 or 1.

A352501 a(n) is the distance from n to the nearest integer that can be added to n without carries in balanced ternary.

Original entry on oeis.org

0, 1, 1, 2, 1, 1, 2, 4, 4, 5, 4, 4, 2, 1, 1, 2, 4, 4, 5, 7, 10, 11, 13, 10, 11, 13, 13, 14, 13, 13, 11, 10, 13, 11, 10, 7, 5, 4, 4, 2, 1, 1, 2, 4, 4, 5, 7, 10, 11, 13, 10, 11, 13, 13, 14, 16, 19, 20, 22, 28, 29, 31, 31, 32, 34, 37, 38, 40, 28, 29, 31, 31, 32
Offset: 0

Views

Author

Rémy Sigrist, Apr 28 2022

Keywords

Comments

Two integers can be added without carries in balanced ternary if they have no equal nonzero digit at the same position.

Examples

			For n = 7:
- the numbers k around 7, alongside their distance to 7, balanced ternary expansion and whether they require carries when added to 7, are:
      k   d  bter(k)  carries?
      --  -  -------  --------
       3  4       10  no
       4  3       11  yes
       5  2      1TT  yes
       6  1      1T0  yes
       7  0      1T1  yes
       8  1      10T  yes
       9  2      100  yes
      10  3      101  yes
      11  4      11T  yes
- so a(7) = 4.
		

Crossrefs

Programs

  • PARI
    ok(u,v) = { while (u && v, my (uu=[0,+1,-1][1+u%3], vv=[0,+1,-1][1+v%3]); if (abs(uu+vv)>1, return (0)); u=(u-uu)/3; v=(v-vv)/3); return (1) }
    a(n) = for (d=0, oo, if (ok(n, n-d) || ok(n, n+d), return (d)))

Formula

a(n) = 1 iff n > 0 and n belongs to A003462 or A007051.
a(3*n) = 3*a(n)+1 for any n > 0.
Showing 1-2 of 2 results.