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-10 of 60 results. Next

A330740 a(n) = min(n, A004488(n)), where A004488(n) is base-3 sum n+n without carries.

Original entry on oeis.org

0, 1, 1, 3, 4, 5, 3, 5, 4, 9, 10, 11, 12, 13, 14, 15, 16, 17, 9, 11, 10, 15, 17, 16, 12, 14, 13, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 27, 29, 28, 33, 35, 34, 30, 32, 31, 45, 47, 46, 51, 53, 52, 48, 50, 49, 36, 38, 37, 42, 44, 43, 39, 41, 40, 81
Offset: 0

Views

Author

Antti Karttunen, Jan 11 2020

Keywords

Comments

After the initial zero, sequence contains only terms of A132141, each appearing exactly twice.

Crossrefs

Central diagonal of A325825 (after the initial zero).

Programs

  • PARI
    A330740(n) = min(n,subst(Pol(apply(x->(3-x)%3, digits(n, 3)), 'x), 'x, 3));

Formula

a(n) = min(n, A004488(n)).

A263273 Bijective base-3 reverse: a(0) = 0; for n >= 1, a(n) = A030102(A038502(n)) * A038500(n).

Original entry on oeis.org

0, 1, 2, 3, 4, 7, 6, 5, 8, 9, 10, 19, 12, 13, 22, 21, 16, 25, 18, 11, 20, 15, 14, 23, 24, 17, 26, 27, 28, 55, 30, 37, 64, 57, 46, 73, 36, 31, 58, 39, 40, 67, 66, 49, 76, 63, 34, 61, 48, 43, 70, 75, 52, 79, 54, 29, 56, 33, 38, 65, 60, 47, 74, 45, 32, 59, 42, 41, 68, 69, 50, 77, 72, 35, 62, 51, 44, 71, 78, 53, 80, 81
Offset: 0

Views

Author

Antti Karttunen, Dec 05 2015

Keywords

Comments

Here the base-3 reverse has been adjusted so that the maximal suffix of trailing zeros (in base-3 representation A007089) stays where it is at the right side, and only the section from the most significant digit to the least significant nonzero digit is reversed, thus making this sequence a self-inverse permutation of nonnegative integers.
Because successive powers of 3 and 9 modulo 2, 4 and 8 are always either constant 1, 1, 1, ... or alternating 1, -1, 1, -1, ... it implies similar simple divisibility rules for 2, 4 and 8 in base 3 as e.g. 3, 9 and 11 have in decimal base (see the Wikipedia-link). As these rules do not depend on which direction they are applied from, it means that this bijection preserves the fact whether a number is divisible by 2, 4 or 8, or whether it is not. Thus natural numbers are divided to several subsets, each of which is closed with respect to this bijection. See the Crossrefs section for permutations obtained from these sections.
When polynomials over GF(3) are encoded as natural numbers (coefficients presented with the digits of the base-3 expansion of n), this bijection works as a multiplicative automorphism of the ring GF(3)[X]. This follows from the fact that as there are no carries involved, the multiplication (and thus also the division) of such polynomials could be as well performed by temporarily reversing all factors (like they were seen through mirror). This implies also that the sequences A207669 and A207670 are closed with respect to this bijection.

Examples

			For n = 15, A007089(15) = 120. Reversing this so that the trailing zero stays at the right yields 210 = A007089(21), thus a(15) = 21 and vice versa, a(21) = 15.
		

Crossrefs

Bisections: A264983, A264984.
Permutations induced by various sections: A263272 (a(2n)/2), A264974 (a(4n)/4), A264978 (a(8n)/8), A264985, A264989.
Cf. also A004488, A140263, A140264, A246207, A246208 (other base-3 related permutations).

Programs

  • Mathematica
    r[n_] := FromDigits[Reverse[IntegerDigits[n, 3]], 3]; b[n_] := n/ 3^IntegerExponent[n, 3]; c[n_] := n/b[n]; a[0]=0; a[n_] := r[b[n]]*c[n]; Table[a[n], {n, 0, 80}] (* Jean-François Alcover, Dec 29 2015 *)
  • Python
    from sympy import factorint
    from sympy.ntheory.factor_ import digits
    from operator import mul
    def a030102(n): return 0 if n==0 else int(''.join(map(str, digits(n, 3)[1:][::-1])), 3)
    def a038502(n):
        f=factorint(n)
        return 1 if n==1 else reduce(mul, [1 if i==3 else i**f[i] for i in f])
    def a038500(n): return n/a038502(n)
    def a(n): return 0 if n==0 else a030102(a038502(n))*a038500(n) # Indranil Ghosh, May 22 2017
  • Scheme
    (define (A263273 n) (if (zero? n) n (* (A030102 (A038502 n)) (A038500 n))))
    

Formula

a(0) = 0; for n >= 1, a(n) = A030102(A038502(n)) * A038500(n).
Other identities. For all n >= 0:
a(3*n) = 3*a(n).
A000035(a(n)) = A000035(n). [This permutation preserves the parity of n.]
A010873(a(n)) = 0 if and only if A010873(n) = 0. [See the comments section.]

A225901 Write n in factorial base, then replace each nonzero digit d of radix k with k-d.

Original entry on oeis.org

0, 1, 4, 5, 2, 3, 18, 19, 22, 23, 20, 21, 12, 13, 16, 17, 14, 15, 6, 7, 10, 11, 8, 9, 96, 97, 100, 101, 98, 99, 114, 115, 118, 119, 116, 117, 108, 109, 112, 113, 110, 111, 102, 103, 106, 107, 104, 105, 72, 73, 76, 77, 74, 75, 90, 91, 94, 95, 92, 93, 84, 85, 88, 89, 86, 87, 78, 79, 82, 83, 80, 81, 48, 49, 52, 53, 50, 51, 66, 67, 70, 71, 68
Offset: 0

Views

Author

Paul Tek, May 20 2013

Keywords

Comments

Analogous to A004488 or A048647 for the factorial base.
A self-inverse permutation of the natural numbers.
From Antti Karttunen, Aug 16-29 2016: (Start)
Consider the following way to view a factorial base representation of nonnegative integer n. For each nonzero digit d_i present in the factorial base representation of n (where i is the radix = 2.. = one more than 1-based position from the right), we place a pebble to the level (height) d_i at the corresponding column i of the triangular diagram like below, while for any zeros the corresponding columns are left empty:
.
Level
6 o
─ ─
5 . .
─ ─ ─
4 . . .
─ ─ ─ ─
3 . . . .
─ ─ ─ ─ ─
2 . . o . .
─ ─ ─ ─ ─ ─
1 . o . . o o
─ ─ ─ ─ ─ ─ ─
Radix: 7 6 5 4 3 2
Digits: 6 1 2 0 1 1 = A007623(4491)
Instead of levels, we can observe on which "slope" each pebble (nonzero digit) is located at. Formally, the slope of nonzero digit d_i with radix i is (i - d_i). Thus in above example, both the most significant digit (6) and the least significant 1 are on slope 1 (called "maximal slope", because it contains digits that are maximal allowed in those positions), while the second 1 from the right is on slope 2 ("submaximal slope").
This involution (A225901) sends each nonzero digit at level k to the slope k (and vice versa) by flipping such a diagram by the shallow diagonal axis that originates from the bottom right corner. Thus, from above diagram we obtain:
Slope (= digit's radix - digit's value)
1
2 .
3 . .╲
4 . .╲o╲
5 . .╲.╲.╲
6 . .╲.╲o╲.╲
. .╲.╲.╲.╲o╲
o╲.╲.╲.╲.╲o╲
-----------------
1 5 3 0 2 1 = A007623(1397)
and indeed, a(4491) = 1397 and a(1397) = 4491.
Thus this permutation maps between polynomial encodings A275734 & A275735 and all the respective sequences obtained from them, where the former set of sequences are concerned with the "slopes" and the latter set with the "levels" of the factorial base representation. See the Crossrefs section.
Sequences A231716 and A275956 are closed with respect to this sequence, in other words, for all n, a(A231716(n)) is a term of A231716 and a(A275956(n)) is a term of A275956.
(End)

Examples

			a(1000) = a(1*6! + 2*5! + 1*4! + 2*3! + 2*2!) = (7-1)*6! + (6-2)*5! + (5-1)*4! + (4-2)*3! + (3-2)*2! = 4910.
a(1397) = a(1*6! + 5*5! + 3*4! + 0*3! + 2*2! + 1*1!) = (7-1)*6! + (6-5)*5! + (5-3)*4! + (3-2)*2! + (2-1)*1! = 4491.
		

Crossrefs

Cf. A275959 (fixed points), A231716, A275956.
This involution maps between the following sequences related to "levels" and "slopes" (see comments): A275806 <--> A060502, A257511 <--> A260736, A264990 <--> A275811, A275729 <--> A275728, A275948 <--> A275946, A275949 <--> A275947, A275964 <--> A275962, A059590 <--> A276091.

Programs

  • Mathematica
    b = MixedRadix[Reverse@ Range[2, 12]]; Table[FromDigits[Map[Boole[# > 0] &, #] (Reverse@ Range[2, Length@ # + 1] - #), b] &@ IntegerDigits[n, b], {n, 0, 82}] (* Version 10.2, or *)
    f[n_] := Block[{a = {{0, n}}}, Do[AppendTo[a, {First@ #, Last@ #} &@ QuotientRemainder[a[[-1, -1]], Times @@ Range[# - i]]], {i, 0, #}] &@ NestWhile[# + 1 &, 0, Times @@ Range[# + 1] <= n &]; Most@ Rest[a][[All, 1]] /. {} -> {0}]; g[w_List] := Total[Times @@@ Transpose@ {Map[Times @@ # &, Range@ Range[0, Length@ w]], Reverse@ Append[w, 0]}]; Table[g[Map[Boole[# > 0] &, #] (Reverse@ Range[2, Length@ # + 1] - #)] &@ f@ n, {n, 0, 82}] (* Michael De Vlieger, Aug 29 2016 *)
  • PARI
    a(n)=my(s=0,d,k=2);while(n,d=n%k;n=n\k;if(d,s=s+(k-d)*(k-1)!);k=k+1);return(s)
    
  • Python
    from sympy import factorial as f
    def a(n):
        s=0
        k=2
        while(n):
            d=n%k
            n=(n//k)
            if d: s=s+(k - d)*f(k - 1)
            k+=1
        return s
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 19 2017
  • Scheme
    (define (A225901 n) (let loop ((n n) (z 0) (m 2) (f 1)) (cond ((zero? n) z) (else (loop (quotient n m) (if (zero? (modulo n m)) z (+ z (* f (- m (modulo n m))))) (+ 1 m) (* f m))))))
    ;; One implementing the first recurrence, with memoization-macro definec:
    (definec (A225901 n) (if (zero? n) n (+ (A276091 (A275736 n)) (A153880 (A225901 (A257684 n))))))
    ;; Antti Karttunen, Aug 29 2016
    

Formula

From Antti Karttunen, Aug 29 2016: (Start)
a(0) = 0; for n >= 1, a(n) = A276091(A275736(n)) + A153880(a(A257684(n))).
or, for n >= 1, a(n) = A276149(n) + a(A257687(n)).
(End)
Other identities. For n >= 0:
a(n!) = A001563(n).
a(n!-1) = A007489(n-1).
From Antti Karttunen, Aug 16 2016: (Start)
A275734(a(n)) = A275735(n) and vice versa, A275735(a(n)) = A275734(n).
A060130(a(n)) = A060130(n). [The flip preserves the number of nonzero digits.]
A153880(n) = a(A255411(a(n))) and A255411(n) = a(A153880(a(n))). [This involution conjugates between the two fundamental factorial base shifts.]
a(n) = A257684(a(A153880(n))) = A266193(a(A255411(n))). [Follows from above.]
A276011(n) = A273662(a(A273670(n))).
A276012(n) = A273663(a(A256450(n))).
(End)

A289814 A binary encoding of the twos in ternary representation of n (see Comments for precise definition).

Original entry on oeis.org

0, 0, 1, 0, 0, 1, 2, 2, 3, 0, 0, 1, 0, 0, 1, 2, 2, 3, 4, 4, 5, 4, 4, 5, 6, 6, 7, 0, 0, 1, 0, 0, 1, 2, 2, 3, 0, 0, 1, 0, 0, 1, 2, 2, 3, 4, 4, 5, 4, 4, 5, 6, 6, 7, 8, 8, 9, 8, 8, 9, 10, 10, 11, 8, 8, 9, 8, 8, 9, 10, 10, 11, 12, 12, 13, 12, 12, 13, 14, 14, 15, 0
Offset: 0

Views

Author

Rémy Sigrist, Jul 12 2017

Keywords

Comments

The ones in the binary representation of a(n) correspond to the twos in the ternary representation of n; for example: ternary(42) = 1120 and binary(a(42)) = 10 (a(42) = 2).
See A289813 for the sequence encoding the ones in ternary representation of n and additional comments.

Examples

			The first values, alongside the ternary representation of n, and the binary representation of a(n), are:
n       a(n)    ternary(n)  binary(a(n))
--      ----    ----------  ------------
0       0       0           0
1       0       1           0
2       1       2           1
3       0       10          0
4       0       11          0
5       1       12          1
6       2       20          10
7       2       21          10
8       3       22          11
9       0       100         0
10      0       101         0
11      1       102         1
12      0       110         0
13      0       111         0
14      1       112         1
15      2       120         10
16      2       121         10
17      3       122         11
18      4       200         100
19      4       201         100
20      5       202         101
21      4       210         100
22      4       211         100
23      5       212         101
24      6       220         110
25      6       221         110
26      7       222         111
		

Crossrefs

Programs

  • Mathematica
    Table[FromDigits[#, 2] &[IntegerDigits[n, 3] /. d_ /; d > 0 :> d - 1], {n, 0, 81}] (* Michael De Vlieger, Jul 20 2017 *)
  • PARI
    a(n) = my (d=digits(n,3)); fromdigits(vector(#d, i, if (d[i]==2, 1, 0)), 2)
    
  • PARI
    a(n) = fromdigits(digits(n, 3)\2, 2); \\ Ruud H.G. van Tol, May 08 2024
    
  • Python
    from sympy.ntheory.factor_ import digits
    def a(n):
        d = digits(n, 3)[1:]
        return int("".join('1' if i == 2 else '0' for i in d), 2)
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jul 20 2017

Formula

a(0) = 0.
a(3*n) = 2 * a(n).
a(3*n+1) = 2 * a(n).
a(3*n+2) = 2 * a(n) + 1.
Also, a(n) = A289813(A004488(n)).
A053735(n) = A000120(A289813(n)) + 2*A000120(a(n)). - Antti Karttunen, Jul 20 2017

A117966 Balanced ternary enumeration (based on balanced ternary representation) of integers; write n in ternary and then replace 2's with (-1)'s.

Original entry on oeis.org

0, 1, -1, 3, 4, 2, -3, -2, -4, 9, 10, 8, 12, 13, 11, 6, 7, 5, -9, -8, -10, -6, -5, -7, -12, -11, -13, 27, 28, 26, 30, 31, 29, 24, 25, 23, 36, 37, 35, 39, 40, 38, 33, 34, 32, 18, 19, 17, 21, 22, 20, 15, 16, 14, -27, -26, -28, -24, -23, -25, -30, -29, -31, -18, -17, -19, -15, -14, -16, -21, -20, -22, -36
Offset: 0

Views

Author

Keywords

Comments

As the graph demonstrates, there are large discontinuities in the sequence between terms 3^i-1 and 3^i, and between terms 2*3^i-1 and 2*3^i. - N. J. A. Sloane, Jul 03 2016

Examples

			7 in base 3 is 21; changing the 2 to a (-1) gives (-1)*3+1 = -2, so a(7) = -2. I.e., the number of -2 according to the balanced ternary enumeration is 7, which can be obtained by replacing every -1 by 2 in the balanced ternary representation (or expansion) of -2, which is -1,1.
		

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175; 2nd. ed. pp. 190-193.

Crossrefs

Programs

  • Maple
    f:= proc(n) local L,i;
       L:= subs(2=-1,convert(n,base,3));
       add(L[i]*3^(i-1),i=1..nops(L))
    end proc:
    map(f, [$0..100]);
    # alternate:
    N:= 100: # to get a(0) to a(N)
    g:= 0:
    for n from 1 to ceil(log[3](N+1)) do
    g:= convert(series(3*subs(x=x^3,g)*(1+x+x^2)+x/(1+x+x^2),x,3^n+1),polynom);
    od:
    seq(coeff(g,x,j),j=0..N); # Robert Israel, Nov 17 2015
    # third Maple program:
    a:= proc(n) option remember; `if`(n=0, 0,
          3*a(iquo(n, 3, 'r'))+`if`(r=2, -1, r))
        end:
    seq(a(n), n=0..3^4-1);  # Alois P. Heinz, Aug 14 2019
  • Mathematica
    Map[FromDigits[#, 3] &, IntegerDigits[#, 3] /. 2 -> -1 & /@ Range@ 80] (* Michael De Vlieger, Nov 17 2015 *)
  • PARI
    a(n) = subst(Pol(apply(x->if(x == 2, -1, x), digits(n,3)), 'x), 'x, 3)
    vector(73, i, a(i-1))  \\ Gheorghe Coserea, Nov 17 2015
    
  • Python
    def a(n):
        if n==0: return 0
        if n%3==0: return 3*a(n//3)
        elif n%3==1: return 3*a((n - 1)//3) + 1
        else: return 3*a((n - 2)//3) - 1
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017

Formula

a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n+2) = 3a(n)-1.
G.f. satisfies A(x) = 3*A(x^3)*(1+x+x^2) + x/(1+x+x^2). - corrected by Robert Israel, Nov 17 2015
A004488(n) = a(n)^{-1}(-a(n)). I.e., if a(n) <= 0, A004488(n) = A117967(-a(n)) and if a(n) > 0, A004488(n) = A117968(a(n)).
a(n) = n - 3 * A005836(A289814(n) + 1). - Andrey Zabolotskiy, Nov 11 2019

Extensions

Name corrected by Andrey Zabolotskiy, Nov 10 2019

A289813 A binary encoding of the ones in ternary representation of n (see Comments for precise definition).

Original entry on oeis.org

0, 1, 0, 2, 3, 2, 0, 1, 0, 4, 5, 4, 6, 7, 6, 4, 5, 4, 0, 1, 0, 2, 3, 2, 0, 1, 0, 8, 9, 8, 10, 11, 10, 8, 9, 8, 12, 13, 12, 14, 15, 14, 12, 13, 12, 8, 9, 8, 10, 11, 10, 8, 9, 8, 0, 1, 0, 2, 3, 2, 0, 1, 0, 4, 5, 4, 6, 7, 6, 4, 5, 4, 0, 1, 0, 2, 3, 2, 0, 1, 0, 16
Offset: 0

Views

Author

Rémy Sigrist, Jul 12 2017

Keywords

Comments

The ones in the binary representation of a(n) correspond to the ones in the ternary representation of n; for example: ternary(42) = 1120 and binary(a(42)) = 1100 (a(42) = 12).
See A289814 for the sequence encoding the twos in ternary representation of n.
By design, a(n) AND A289814(n) = 0 (where AND stands for the bitwise AND operator).
See A289831 for the sum of this sequence and A289814.
For each pair of numbers without common bits in base 2 representation, say x and y, there is a unique index, say n, such that a(n) = x and A289814(n) = y; in fact, n = A289869(x,y).
The scatterplot of this sequence vs A289814 looks like a Sierpinski triangle pivoted to the side.
For any t > 0: we can adapt the algorithm used here and in A289814 in order to uniquely enumerate every tuple of t numbers mutually without common bits in base 2 representation.

Examples

			The first values, alongside the ternary representation of n, and the binary representation of a(n), are:
n       a(n)    ternary(n)  binary(a(n))
--      ----    ----------  ------------
0       0       0           0
1       1       1           1
2       0       2           0
3       2       10          10
4       3       11          11
5       2       12          10
6       0       20          0
7       1       21          1
8       0       22          0
9       4       100         100
10      5       101         101
11      4       102         100
12      6       110         110
13      7       111         111
14      6       112         110
15      4       120         100
16      5       121         101
17      4       122         100
18      0       200         0
19      1       201         1
20      0       202         0
21      2       210         10
22      3       211         11
23      2       212         10
24      0       220         0
25      1       221         1
26      0       222         0
		

Crossrefs

Programs

  • Mathematica
    Table[FromDigits[#, 2] &[IntegerDigits[n, 3] /. 2 -> 0], {n, 0, 81}] (* Michael De Vlieger, Jul 20 2017 *)
  • PARI
    a(n) = my (d=digits(n,3)); fromdigits(vector(#d, i, if (d[i]==1, 1, 0)), 2)
    
  • PARI
    a(n) = fromdigits(digits(n, 3)%2, 2); \\ Ruud H.G. van Tol, May 08 2024
    
  • Python
    from sympy.ntheory.factor_ import digits
    def a(n):
        d = digits(n, 3)[1:]
        return int("".join('1' if i==1 else '0' for i in d), 2)
    print([a(n) for n in range(51)]) # Indranil Ghosh, Jul 20 2017

Formula

a(0) = 0.
a(3*n) = 2 * a(n).
a(3*n+1) = 2 * a(n) + 1.
a(3*n+2) = 2 * a(n).
Also, a(n) = A289814(A004488(n)).
A053735(n) = A000120(a(n)) + 2*A000120(A289814(n)). - Antti Karttunen, Jul 20 2017

A117967 Positive part of inverse of A117966; write n in balanced ternary and then replace (-1)'s with 2's.

Original entry on oeis.org

0, 1, 5, 3, 4, 17, 15, 16, 11, 9, 10, 14, 12, 13, 53, 51, 52, 47, 45, 46, 50, 48, 49, 35, 33, 34, 29, 27, 28, 32, 30, 31, 44, 42, 43, 38, 36, 37, 41, 39, 40, 161, 159, 160, 155, 153, 154, 158, 156, 157, 143, 141, 142, 137, 135, 136, 140, 138, 139, 152, 150, 151, 146
Offset: 0

Views

Author

Keywords

Examples

			7 in balanced ternary is 1(-1)1, changing to 121 ternary is 16, so a(7)=16.
		

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175

Crossrefs

Cf. A117966. a(n) = A004488(A117968(n)). Bisection of A140263. A140267 gives the same sequence in ternary.

Programs

  • Maple
    a:= proc(n) local d, i, m, r; m:=n; r:=0;
          for i from 0 while m>0 do
             d:= irem(m, 3, 'm');
             if d=2 then m:=m+1 fi;
             r:= r+d*3^i
          od; r
        end:
    seq(a(n), n=0..100);  # Alois P. Heinz, May 11 2015
  • Mathematica
    a[n_] := Module[{d, i, m = n, r = 0}, For[i = 0, m > 0, i++, {m, d} = QuotientRemainder[m, 3]; If[d == 2, m++]; r = r + d*3^i]; r];
    a /@ Range[0, 100] (* Jean-François Alcover, Jan 05 2021, after Alois P. Heinz *)
  • Python
    from sympy.ntheory.factor_ import digits
    def a004488(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3)
    def a117968(n):
        if n==1: return 2
        if n%3==0: return 3*a117968(n/3)
        elif n%3==1: return 3*a117968((n - 1)/3) + 2
        else: return 3*a117968((n + 1)/3) + 1
    def a(n): return 0 if n==0 else a004488(a117968(n)) # Indranil Ghosh, Jun 06 2017
  • Scheme
    ;; Two alternative definitions in MIT/GNU Scheme, defined for whole Z:
    (define (A117967 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967 (- z)))) (else (let* ((lp3 (expt 3 (A062153 z))) (np3 (* 3 lp3))) (if (< (* 2 z) np3) (+ lp3 (A117967 (- z lp3))) (+ np3 (A117967 (- z np3))))))))
    (define (A117967v2 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967v2 (- z)))) ((zero? (modulo z 3)) (* 3 (A117967v2 (/ z 3)))) ((= 1 (modulo z 3)) (+ (* 3 (A117967v2 (/ (- z 1) 3))) 1)) (else (+ (* 3 (A117967v2 (/ (+ z 1) 3))) 2))))
    ;; Antti Karttunen, May 19 2008
    

Formula

a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n-1) = 3a(n)+2.
If one adds this clause, then the function is defined on the whole Z: If n<0, then a(n) = A004488(a(-n)) (or equivalently: a(n) = A117968(-n)) and then it holds that a(A117966(n)) = n. - Antti Karttunen, May 19 2008

A117968 Negative part of inverse of A117966; write -n in balanced ternary and then replace (-1)'s with 2's.

Original entry on oeis.org

2, 7, 6, 8, 22, 21, 23, 19, 18, 20, 25, 24, 26, 67, 66, 68, 64, 63, 65, 70, 69, 71, 58, 57, 59, 55, 54, 56, 61, 60, 62, 76, 75, 77, 73, 72, 74, 79, 78, 80, 202, 201, 203, 199, 198, 200, 205, 204, 206, 193, 192, 194, 190, 189, 191, 196, 195, 197, 211, 210, 212, 208, 207
Offset: 1

Views

Author

Keywords

Examples

			-7 in balanced ternary is (-1)1(-1), changing to 212 ternary is 23, so a(7)=23.
		

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175

Crossrefs

Cf. A117966. a(n) = A004488(A117967(n)). Bisection of A140263. A140268 gives the same sequence in ternary.

Programs

  • Python
    def a(n):
        if n==1: return 2
        if n%3==0: return 3*a(n//3)
        elif n%3==1: return 3*a((n - 1)//3) + 2
        else: return 3*a((n + 1)//3) + 1
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 06 2017

Formula

a(1) = 2, a(3n) = 3a(n), a(3n+1) = 3a(n)+2, a(3n-1) = 3a(n)+1.

A140267 Nonnegative integers in balanced ternary representation (with 2 standing for -1 digit).

Original entry on oeis.org

0, 1, 12, 10, 11, 122, 120, 121, 102, 100, 101, 112, 110, 111, 1222, 1220, 1221, 1202, 1200, 1201, 1212, 1210, 1211, 1022, 1020, 1021, 1002, 1000, 1001, 1012, 1010, 1011, 1122, 1120, 1121, 1102, 1100, 1101, 1112, 1110, 1111, 12222, 12220, 12221
Offset: 0

Views

Author

Antti Karttunen, May 19 2008, prompted by Eric Angelini's posting on SeqFan mailing list on Sep 15 2005

Keywords

Comments

Sequence A117967 in ternary. (See there for more references.)
From Daniel Forgues, Mar 22 2010: (Start)
The balanced ternary digits {-1, 0, +1} (balanced trits) of a(n) are being represented by {2, 0, 1} respectively in this sequence.
The sign of a(n) is given by the sign of its leading trit.
The number k, k >= 0, of trailing "0"s of a(n) indicates that a(n) is divisible by 3^k.
a(n) is even/odd if it has an even/odd count of nonzero trits. (End)

Examples

			For example a(2) = 12, as 1*3 + -1*1 = 2. Similarly, a(19) = 1201, as 1*27 + -1*9 + 0*3 + 1*1 = 19.
		

Crossrefs

a(n) = A007089(A117967(n)). Cf. A140268.

Programs

  • Python
    from sympy.ntheory.factor_ import digits
    def a004488(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3)
    def a117968(n):
        if n==1: return 2
        if n%3==0: return 3*a117968(n/3)
        elif n%3==1: return 3*a117968((n - 1)/3) + 2
        else: return 3*a117968((n + 1)/3) + 1
    def a117967(n): return 0 if n==0 else a004488(a117968(n))
    def a(n): return int("".join(map(str, digits(a117967(n), 3)[1:]))) # Indranil Ghosh, Jun 06 2017

Extensions

Definition edited by Daniel Forgues, Mar 24 2010

A055120 Digital complement of n (replace each nonzero digit d with 10-d).

Original entry on oeis.org

0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 90, 99, 98, 97, 96, 95, 94, 93, 92, 91, 80, 89, 88, 87, 86, 85, 84, 83, 82, 81, 70, 79, 78, 77, 76, 75, 74, 73, 72, 71, 60, 69, 68, 67, 66, 65, 64, 63, 62, 61, 50, 59, 58, 57, 56, 55, 54, 53, 52, 51, 40, 49, 48, 47, 46, 45, 44, 43, 42, 41, 30, 39
Offset: 0

Views

Author

Henry Bottomley, Apr 19 2000

Keywords

Comments

a(n) = -n in carryless arithmetic mod 10 - that is, n + a(n) = 0 (cf. A169894). - N. J. A. Sloane, Aug 03 2010

Examples

			a(11) = 99 because 1 + 9 = 0 mod 10 for each digit.
a(20) = 80 because 2 + 8 = 0 mod 10 and 0 + 0 = 0 mod 10.
		

Crossrefs

Column k=10 of A248813.

Programs

  • Haskell
    a055120 = foldl f 0 . reverse . unfoldr g where
       f v d = if d == 0 then 10 * v else 10 * v + 10 - d
       g x = if x == 0 then Nothing else Just $ swap $ divMod x 10
    -- Reinhard Zumkeller, Oct 04 2011
    
  • Maple
    f:=proc(n) local t0,t1,i;
    t0:=0; t1:=convert(n,base,10);
    for i from 1 to nops(t1) do
    if t1[i]>0 then t0:=t0+(10-t1[i])*10^(i-1); fi;
    od:
    RETURN(t0);
    end;
    # N. J. A. Sloane, Jan 21 2011
  • Mathematica
    a[n_] := FromDigits[ IntegerDigits[n] /. d_?Positive -> 10-d]; Table[a[n], {n, 0, 100}](* Jean-François Alcover, Nov 28 2011 *)
  • PARI
    a(n)=fromdigits(apply(d->if(d,10-d,0),digits(n))) \\ Charles R Greathouse IV, Feb 08 2017
    
  • Python
    def A055120(n): return int(''.join(str(10-int(d)) if d != '0' else d for d in str(n))) # Chai Wah Wu, Apr 03 2021

Formula

From Robert Israel, Sep 04 2017: (Start)
a(10*n) = 10*a(n).
a(10*n+j) = 10*a(n) + 10 - j for 1 <= j <= 9.
G.f. g(x) satisfies g(x) = 10*(1+x+x^2+...+x^9)*g(x^10) + (9*x+8*x^2+7*x^3+6*x^4+5*x^5+4*x^6+3*x^7+2*x^8+x^9)/(1-x^10).
(End)
Showing 1-10 of 60 results. Next