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.

A353158 a(n) is the distance from n to the nearest integer that can be added to n without carries in base 3.

Original entry on oeis.org

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

Views

Author

Rémy Sigrist, Apr 27 2022

Keywords

Examples

			For n = 42:
- the numbers k around 42, alongside their distance to 42, ternary expansion and whether they require carries when added to 42, are:
      k   d  ter(k)  carries?
      --  -  ------  --------
      38  4    1102  no
      39  3    1110  yes
      40  2    1111  yes
      41  1    1112  yes
      42  0    1120  yes
      43  1    1121  yes
      44  2    1122  yes
      45  3    1200  yes
      46  4    1201  yes
- so a(42) = 4.
		

Crossrefs

Cf. A005836 (positions of zeros), A167877, A353157 (binary variant).

Programs

  • PARI
    ok(u,v) = sumdigits(u+v,3)==sumdigits(u,3)+sumdigits(v,3)
    a(n) = { for (d=0, oo, if (ok(n, n-d) || ok(n, n+d), return (d))) }

Formula

a(n) = 0 iff n belongs to A005836.