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.

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

This page as a plain text file.
%I A352501 #110 May 01 2022 11:42:30
%S A352501 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,
%T A352501 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,
%U A352501 19,20,22,28,29,31,31,32,34,37,38,40,28,29,31,31,32
%N A352501 a(n) is the distance from n to the nearest integer that can be added to n without carries in balanced ternary.
%C A352501 Two integers can be added without carries in balanced ternary if they have no equal nonzero digit at the same position.
%H A352501 Rémy Sigrist, <a href="/A352501/b352501.txt">Table of n, a(n) for n = 0..9841</a>
%H A352501 Wikipedia, <a href="https://en.wikipedia.org/wiki/Balanced_ternary">Balanced ternary</a>
%F A352501 a(n) = 1 iff n > 0 and n belongs to A003462 or A007051.
%F A352501 a(3*n) = 3*a(n)+1 for any n > 0.
%e A352501 For n = 7:
%e A352501 - the numbers k around 7, alongside their distance to 7, balanced ternary expansion and whether they require carries when added to 7, are:
%e A352501       k   d  bter(k)  carries?
%e A352501       --  -  -------  --------
%e A352501        3  4       10  no
%e A352501        4  3       11  yes
%e A352501        5  2      1TT  yes
%e A352501        6  1      1T0  yes
%e A352501        7  0      1T1  yes
%e A352501        8  1      10T  yes
%e A352501        9  2      100  yes
%e A352501       10  3      101  yes
%e A352501       11  4      11T  yes
%e A352501 - so a(7) = 4.
%o A352501 (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) }
%o A352501 a(n) = for (d=0, oo, if (ok(n, n-d) || ok(n, n+d), return (d)))
%Y A352501 Cf. A003462, A007051, A059095, A353158.
%K A352501 nonn,base
%O A352501 0,4
%A A352501 _Rémy Sigrist_, Apr 28 2022