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-9 of 9 results.

A035327 Write n in binary, interchange 0's and 1's, convert back to decimal.

Original entry on oeis.org

1, 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46
Offset: 0

Views

Author

Keywords

Comments

For n>0: largest m<=n such that no carry occurs when adding m to n in binary arithmetic: A003817(n+1) = a(n) + n = a(n) XOR n. - Reinhard Zumkeller, Nov 14 2009
a(0) could be considered to be 0 (it was set so from 2004 to 2008) if the binary representation of zero was chosen to be the empty string. - Jason Kimberley, Sep 19 2011
For n > 0: A240857(n,a(n)) = 0. - Reinhard Zumkeller, Apr 14 2014
This is a base-2 analog of A048379. Another variant, without converting back to decimal, is given in A256078. - M. F. Hasler, Mar 22 2015
For n >= 2, a(n) is the least nonnegative k that must be added to n+1 to make a power of 2. Hence in a single-elimination tennis tournament with n entrants, a(n-1) is the number of players given a bye in round one, so that the number of players remaining at the start of round two is a power of 2. For example, if 39 players register, a(38)=25 players receive a round-one bye leaving 14 to play, so that round two will have 25+(14/2)=32 players. - Mathew Englander, Jan 20 2024

Examples

			8 = 1000 -> 0111 = 111 = 7.
		

Crossrefs

a(n) = A003817(n) - n, for n>0.
Cf. A240857.

Programs

  • Haskell
    a035327 n = if n <= 1 then 1 - n else 2 * a035327 n' + 1 - b
                where (n',b) = divMod n 2
    -- Reinhard Zumkeller, Feb 21 2014
    
  • Julia
    using IntegerSequences
    A035327List(len) = [Bits("NAND", n, n) for n in 0:len]
    println(A035327List(100))  # Peter Luschny, Sep 25 2021
  • Magma
    A035327:=func; // Jason Kimberley, Sep 19 2011
    
  • Maple
    seq(2^(1 + ilog2(max(n, 1))) - 1 - n, n = 0..81); # Emeric Deutsch, Oct 19 2008
    A035327 := n -> `if`(n=0, 1, Bits:-Nand(n, n)):
    seq(A035327(n), n=0..81); # Peter Luschny, Sep 23 2019
  • Mathematica
    Table[BaseForm[FromDigits[(IntegerDigits[i, 2]/.{0->1, 1->0}), 2], 10], {i, 0, 90}]
    Table[BitXor[n, 2^IntegerPart[Log[2, n] + 1] - 1], {n, 100}] (* Alonso del Arte, Jan 14 2006 *)
    Join[{1},Table[2^BitLength[n]-n-1,{n,100}]] (* Paolo Xausa, Oct 13 2023 *)
    Table[FromDigits[IntegerDigits[n,2]/.{0->1,1->0},2],{n,0,90}] (* Harvey P. Dale, May 03 2025 *)
  • PARI
    a(n)=sum(k=1,n,if(bitxor(n,k)>n,1,0)) \\ Paul D. Hanna, Jan 21 2006
    
  • PARI
    a(n) = bitxor(n, 2^(1+logint(max(n,1), 2))-1) \\ Rémy Sigrist, Jan 04 2019
    
  • PARI
    a(n)=if(n, bitneg(n, exponent(n)+1), 1) \\ Charles R Greathouse IV, Apr 13 2020
    
  • Python
    def a(n): return int(''.join('1' if i == '0' else '0' for i in bin(n)[2:]), 2) # Indranil Ghosh, Apr 29 2017
    
  • Python
    def a(n): return 1 if n == 0 else n^((1 << n.bit_length()) - 1)
    print([a(n) for n in range(100)]) # Michael S. Branicky, Sep 28 2021
    
  • Python
    def A035327(n): return (~n)^(-1<Chai Wah Wu, Dec 20 2022
    
  • SageMath
    def a(n):
        if n == 0:
            return 1
        return sum([(1 - b) << s for (s, b) in enumerate(n.bits())])
    [a(n) for n in srange(82)]  # Peter Luschny, Aug 31 2019
    

Formula

a(n) = 2^k - n - 1, where 2^(k-1) <= n < 2^k.
a(n+1) = (a(n)+n) mod (n+1); a(0) = 1. - Reinhard Zumkeller, Jul 22 2002
G.f.: 1 + 1/(1-x)*Sum_{k>=0} 2^k*x^2^(k+1)/(1+x^2^k). - Ralf Stephan, May 06 2003
a(0) = 0, a(2n+1) = 2*a(n), a(2n) = 2*a(n) + 1. - Philippe Deléham, Feb 29 2004
a(n) = number of positive integers k < n such that n XOR k > n. a(n) = n - A006257(n). - Paul D. Hanna, Jan 21 2006
a(n) = 2^{1+floor(log[2](n))}-n-1 for n>=1; a(0)=1. - Emeric Deutsch, Oct 19 2008
a(n) = if n<2 then 1 - n else 2*a(floor(n/2)) + 1 - n mod 2. - Reinhard Zumkeller, Jan 20 2010
a(n) = abs(2*A053644(n) - n - 1). - Mathew Englander, Jan 22 2024

Extensions

More terms from Vit Planocka (planocka(AT)mistral.cz), Feb 01 2003
a(0) corrected by Paolo P. Lava, Oct 22 2007
Definition completed by M. F. Hasler, Mar 22 2015

A359194 Binary complement of 3*n.

Original entry on oeis.org

1, 0, 1, 6, 3, 0, 13, 10, 7, 4, 1, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0, 61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 31, 28, 25, 22, 19, 16, 13, 10, 7, 4, 1, 126, 123, 120, 117, 114, 111, 108, 105, 102, 99, 96, 93, 90, 87, 84, 81, 78, 75, 72, 69, 66, 63, 60, 57
Offset: 0

Views

Author

Joshua Searle, Dec 19 2022

Keywords

Comments

The binary complement takes the binary value of a number and turns any 1s to 0s and vice versa. This is equivalent to subtracting from the next larger Mersenne number.
It is currently unknown whether every starting positive integer, upon iteration, reaches 0.
From M. F. Hasler, Dec 26 2022: (Start)
This map enjoys the following properties:
(P1) a(2*n) = a(n)*2 + 1 (since 3*(2*n) is 3*n shifted one binary digit to the left, and the one's complement yields that of 3*n with a '1' appended).
(P2) As an immediate consequence of (P1), all even-indexed values are odd.
(P3) Also from (P1), by immediate induction we have a(2^n) = 2^n-1 for all n >= 0.
(P4) Also from (P1), a(4*n) = a(n)*4 + 3.
(P5) Similarly, a(4*n+1) = a(n)*4 (because the 1's complement of 3 is 0).
(P6) From (P5), a(n) = 0 for all n in A002450 (= (4^k-1)/3). [For the initial value at n = 0 the discrepancy is explained by the fact that the number 0 should be considered to have zero digits, but here the result is computed with 0 considered to have one binary digit.] (End)

Examples

			a(7) = 10 because 3*7 = 21 = 10101_2, whose binary complement is 01010_2 = 10.
a(42) = 1 because 3*42 = 126 = 1111110_2, whose binary complement is 0000001_2 = 1.
a(52) = 99 by
  3*n        = binary 10011100
  complement = binary 01100011 = 99.
		

Crossrefs

Trisection of A035327.
Cf. A002450, A020988 (indices of 1's).
Cf. A256078.

Programs

  • PARI
    a(n)=if(n, bitneg(3*n, exponent(3*n)+1), 1) \\ Rémy Sigrist, Dec 22 2022
  • Python
    def a(n): return 1 if n == 0 else (m:=3*n)^((1 << m.bit_length()) - 1)
    print([a(n) for n in range(67)]) # Michael S. Branicky, Dec 20 2022
    

Formula

a(n) = A035327(3*n).
a(n) = 0 iff n belongs to A002450 \ {0}. - Rémy Sigrist, Dec 22 2022

A256289 Apply the transformation 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 0 to the digits of n written in base 9; do not convert back to base 10.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 0, 21, 22, 23, 24, 25, 26, 27, 28, 20, 31, 32, 33, 34, 35, 36, 37, 38, 30, 41, 42, 43, 44, 45, 46, 47, 48, 40, 51, 52, 53, 54, 55, 56, 57, 58, 50, 61, 62, 63, 64, 65, 66, 67, 68, 60, 71, 72, 73, 74, 75, 76
Offset: 0

Views

Author

M. F. Hasler, Mar 22 2015

Keywords

Comments

Base 9 variant of A256078 (base 2) and A048379 (base 10). See A256303 - A256308 for bases 3 through 8, and A256299 for the variant where the result is converted back to base 10.

Examples

			a(9) = 21 because 9 = "10" in base 9 becomes "21".
a(80) = 0 because 80 = "88" in base 9 becomes "00".
		

Programs

  • PARI
    A256289(n,b=9)=!n+eval(Strchr(apply(d->(d+1)%b+48, digits(n,b))))

A256303 Apply the transformation 0 -> 1 -> 2 -> 0 to the digits of n written in base 3; do not convert back to base 10.

Original entry on oeis.org

1, 2, 0, 21, 22, 20, 1, 2, 0, 211, 212, 210, 221, 222, 220, 201, 202, 200, 11, 12, 10, 21, 22, 20, 1, 2, 0, 2111, 2112, 2110, 2121, 2122, 2120, 2101, 2102, 2100, 2211, 2212, 2210, 2221, 2222, 2220, 2201, 2202, 2200, 2011, 2012, 2010, 2021, 2022, 2020, 2001
Offset: 0

Views

Author

M. F. Hasler, Mar 22 2015

Keywords

Comments

Base 3 variant of A256078 (base 2) and A048379 (base 10). See A256304 - A256308 for bases 4 through 8, A256289 for base 9, and A256293 for the variant where the result is converted back to base 10.

Examples

			a(3) = 21 because 3 = "10" (in base 3) becomes "21".
a(8) = 0 because 8 = "22" (in base 3) becomes "00".
		

Programs

  • Mathematica
    Table[FromDigits[IntegerDigits[n,3]/.{0->1,1->2,2->0}],{n,0,60}] (* Harvey P. Dale, Jun 17 2022 *)
  • PARI
    A256303(n,b=3)=!n+eval(Strchr(apply(d->(d+1)%b+48, digits(n,b))))

A256308 Apply the transformation 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 0 to the digits of n written in base 8; do not convert back to base 10.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 0, 21, 22, 23, 24, 25, 26, 27, 20, 31, 32, 33, 34, 35, 36, 37, 30, 41, 42, 43, 44, 45, 46, 47, 40, 51, 52, 53, 54, 55, 56, 57, 50, 61, 62, 63, 64, 65, 66, 67, 60, 71, 72, 73, 74, 75, 76, 77, 70, 1, 2, 3, 4
Offset: 0

Views

Author

M. F. Hasler, Mar 22 2015

Keywords

Comments

Base 8 variant of A256078 (base 2) and A048379 (base 10). See A256303 - A256307 for bases 3 through 7, A256289 for base 9, and A256298 for the variant where the result is converted back to base 10.

Examples

			a(8) = 21 because 8 = "10" in base 8 becomes "21".
a(63) = 0 because 63 = "77" in base 8 becomes "00".
		

Programs

  • Mathematica
    Table[FromDigits[IntegerDigits[n,8]/.{0->1,1->2,2->3,3->4,4->5,5->6,6->7,7->0}],{n,0,60}] (* Harvey P. Dale, Mar 29 2015 *)
  • PARI
    A256308(n,b=8)=!n+eval(Strchr(apply(d->(d+1)%b+48, digits(n,b))))

Extensions

Examples corrected by Harvey P. Dale, Mar 29 2015

A256304 Apply the transformation 0 -> 1 -> 2 -> 3 -> 0 to the digits of n written in base 4; do not convert back to base 10.

Original entry on oeis.org

1, 2, 3, 0, 21, 22, 23, 20, 31, 32, 33, 30, 1, 2, 3, 0, 211, 212, 213, 210, 221, 222, 223, 220, 231, 232, 233, 230, 201, 202, 203, 200, 311, 312, 313, 310, 321, 322, 323, 320, 331, 332, 333, 330, 301, 302, 303, 300, 11, 12, 13, 10, 21, 22, 23, 20, 31, 32
Offset: 0

Views

Author

M. F. Hasler, Mar 22 2015

Keywords

Comments

Base 4 variant of A256078 (base 2) and A048379 (base 10). See A256303 - A256308 for bases 3 through 8, A256289 for base 9, and A256294 for the variant where the result is converted back to base 10.

Examples

			a(4) = 21 because 4 = "10" (in base 4) becomes "21".
a(15) = 0 because 15 = "33" (in base 4) becomes "00".
		

Programs

  • PARI
    A256304(n,b=4)=!n+eval(Strchr(apply(d->(d+1)%b+48, digits(n,b))))

A256307 Apply the transformation 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 0 to the digits of n written in base 7; do not convert back to base 10.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 0, 21, 22, 23, 24, 25, 26, 20, 31, 32, 33, 34, 35, 36, 30, 41, 42, 43, 44, 45, 46, 40, 51, 52, 53, 54, 55, 56, 50, 61, 62, 63, 64, 65, 66, 60, 1, 2, 3, 4, 5, 6, 0, 211, 212, 213, 214, 215, 216, 210, 221, 222, 223, 224
Offset: 0

Views

Author

M. F. Hasler, Mar 22 2015

Keywords

Comments

Base 7 variant of A256078 (base 2) and A048379 (base 10). See A256303 - A256308 for bases 3 through 8, A256289 for base 9, and A256297 for the variant where the result is converted back to base 10.

Examples

			a(7) = 21 because 7 = "10" (in base 7) becomes "21".
a(48) = 0 because 48 = "66" (in base 7) becomes "00".
		

Programs

  • Mathematica
    Table[FromDigits[IntegerDigits[n,7]/.{0->1,1->2,2->3,3->4,4->5,5->6,6->0}],{n,0,60}] (* Harvey P. Dale, Oct 09 2023 *)
  • PARI
    A256307(n,b=7)=!n+eval(Strchr(apply(d->(d+1)%b+48, digits(n,b))))

A256305 Apply the transformation 0 -> 1 -> 2 -> 3 -> 4 -> 0 to the digits of n written in base 5; do not convert back to base 10.

Original entry on oeis.org

1, 2, 3, 4, 0, 21, 22, 23, 24, 20, 31, 32, 33, 34, 30, 41, 42, 43, 44, 40, 1, 2, 3, 4, 0, 211, 212, 213, 214, 210, 221, 222, 223, 224, 220, 231, 232, 233, 234, 230, 241, 242, 243, 244, 240, 201, 202, 203, 204, 200, 311, 312, 313, 314, 310, 321, 322, 323
Offset: 0

Views

Author

M. F. Hasler, Mar 22 2015

Keywords

Comments

Base 5 variant of A256078 (base 2) and A048379 (base 10). See A256303 - A256308 for bases 3 through 8, A256289 for base 9, and A256295 for the variant where the result is converted back to base 10.

Examples

			a(5) = 21 because 5 = "10" (in base 5) becomes "21".
a(24) = 0 because 24 = "44" (in base 5) becomes "00".
		

Programs

  • Mathematica
    Table[FromDigits[(IntegerDigits[n,5]+1/.(5->0))],{n,0,60}] (* Harvey P. Dale, Nov 15 2020 *)
  • PARI
    A256305(n,b=5)=!n+eval(Strchr(apply(d->(d+1)%b+48, digits(n,b))))

A256306 Apply the transformation 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 0 to the digits of n written in base 6; do not convert back to base 10.

Original entry on oeis.org

1, 2, 3, 4, 5, 0, 21, 22, 23, 24, 25, 20, 31, 32, 33, 34, 35, 30, 41, 42, 43, 44, 45, 40, 51, 52, 53, 54, 55, 50, 1, 2, 3, 4, 5, 0, 211, 212, 213, 214, 215, 210, 221, 222, 223, 224, 225, 220, 231, 232, 233, 234, 235, 230, 241, 242, 243, 244, 245, 240
Offset: 0

Views

Author

M. F. Hasler, Mar 22 2015

Keywords

Comments

Base 6 variant of A256078 (base 2) and A048379 (base 10). See A256303 - A256308 for bases 3 through 8, A256289 for base 9, and A256296 for the variant where the result is converted back to base 10.

Examples

			a(6) = 21 because 6 = "10" (in base 6) becomes "21".
a(35) = 0 because 35 = "55" (in base 6) becomes "00".
		

Programs

  • PARI
    A256306(n,b=6)=!n+eval(Strchr(apply(d->(d+1)%b+48, digits(n,b))))
Showing 1-9 of 9 results.