login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A352501 a(n) is the distance from n to the nearest integer that can be added to n without carries in balanced ternary. 1
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 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,4

COMMENTS

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

LINKS

Rémy Sigrist, Table of n, a(n) for n = 0..9841

Wikipedia, Balanced ternary

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.

EXAMPLE

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.

PROG

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

CROSSREFS

Cf. A003462, A007051, A059095, A353158.

Sequence in context: A108746 A333270 A333272 * A119558 A333450 A210112

Adjacent sequences: A352498 A352499 A352500 * A352502 A352503 A352504

KEYWORD

nonn,base

AUTHOR

Rémy Sigrist, Apr 28 2022

STATUS

approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified March 22 13:50 EDT 2023. Contains 361430 sequences. (Running on oeis4.)