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.
%I A353158 #12 May 01 2022 11:42:44 %S A353158 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, %T A353158 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, %U A353158 21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4 %N A353158 a(n) is the distance from n to the nearest integer that can be added to n without carries in base 3. %H A353158 Rémy Sigrist, <a href="/A353158/b353158.txt">Table of n, a(n) for n = 0..9841</a> %F A353158 a(n) = 0 iff n belongs to A005836. %e A353158 For n = 42: %e A353158 - the numbers k around 42, alongside their distance to 42, ternary expansion and whether they require carries when added to 42, are: %e A353158 k d ter(k) carries? %e A353158 -- - ------ -------- %e A353158 38 4 1102 no %e A353158 39 3 1110 yes %e A353158 40 2 1111 yes %e A353158 41 1 1112 yes %e A353158 42 0 1120 yes %e A353158 43 1 1121 yes %e A353158 44 2 1122 yes %e A353158 45 3 1200 yes %e A353158 46 4 1201 yes %e A353158 - so a(42) = 4. %o A353158 (PARI) ok(u,v) = sumdigits(u+v,3)==sumdigits(u,3)+sumdigits(v,3) %o A353158 a(n) = { for (d=0, oo, if (ok(n, n-d) || ok(n, n+d), return (d))) } %Y A353158 Cf. A005836 (positions of zeros), A167877, A353157 (binary variant). %K A353158 nonn,base %O A353158 0,6 %A A353158 _Rémy Sigrist_, Apr 27 2022