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.

A175046 Write n in binary, then increase each run of 0's by one 0, and increase each run of 1's by one 1. a(n) is the decimal equivalent of the result.

Original entry on oeis.org

3, 12, 7, 24, 51, 28, 15, 48, 99, 204, 103, 56, 115, 60, 31, 96, 195, 396, 199, 408, 819, 412, 207, 112, 227, 460, 231, 120, 243, 124, 63, 192, 387, 780, 391, 792, 1587, 796, 399, 816, 1635, 3276, 1639, 824, 1651, 828, 415, 224, 451, 908, 455, 920, 1843, 924
Offset: 1

Views

Author

Leroy Quet, Dec 02 2009

Keywords

Comments

A318921 expands the runs in a similar way, and A318921(a(n)) = A001477(n). - Andrew Weimholt, Sep 08 2018
From Chai Wah Wu, Nov 18 2018: (Start)
Let f(k) = Sum_{i=2^k..2^(k+1)-1} a(i), i.e., the sum ranges over all numbers with a (k+1)-bit binary expansion. Thus f(0) = a(1) = 3 and f(1) = a(2) + a(3) = 19.
Then f(k) = 20*6^(k-1) - 2^(k-1) for k > 0.
Proof: by summing over the recurrence relations for a(n) (see formula section), we get f(k+2) = Sum_{i=2^k..2^(k+1)-1} (f(4i) + f(4i+1) + f(4i+2) + f(4i+3)) = Sum_{i=2^k..2^(k+1)-1} (6*a(2i) + 6*a(2i+1) + 4) = 6*f(k+1) + 2^(k+2). Solving this first-order recurrence relation with the initial condition f(1) = 19 shows that f(k) = 20*6^(k-1)-2^(k-1) for k > 0.
(End)

Examples

			6 in binary is 110. Increase each run by one digit to get 11100, which is 28 in decimal. So a(6) = 28.
		

Crossrefs

Cf. A175047, A175048, A324127 (partial sums).
For records see A319422, A319423, A319424.

Programs

  • Haskell
    import Data.List (group)
    a175046 = foldr (\b v -> 2 * v + b) 0 .
              concatMap (\bs@(b:_) -> b : bs) . group . a030308_row
    -- Reinhard Zumkeller, Jul 05 2013
    
  • Mathematica
    a[n_] := (Append[#, #[[1]]]& /@ Split[IntegerDigits[n, 2]]) // Flatten // FromDigits[#, 2]&;
    Array[a, 60] (* Jean-François Alcover, Nov 12 2018 *)
  • PARI
    A175046(n)={for(i=2,#n=binary (n*2+bittest (n,0)),n[i]!=n[i-1]&&n[i-1]*=[1,1]);fromdigits(concat(n),2)} \\ M. F. Hasler, Sep 08 2018
    
  • Python
    from re import split
    def A175046(n):
        return int(''.join(d+'1' if '1' in d else d+'0' for d in split('(0+)|(1+)',bin(n)[2:]) if d != '' and d != None),2) # Chai Wah Wu, Sep 24 2018
    
  • Python
    def a(n):
        b = bin(n)[2:]
        return int(b.replace("01", "001").replace("10", "110") + b[-1], 2)
    print([a(n) for n in range(1, 55)]) # Michael S. Branicky, Dec 07 2021

Formula

2n+1 <= a(n) < 2*(n+1/n)^2; a(n) mod 4 = 3*(n mod 2). - M. F. Hasler, Sep 08 2018
a(n) <= (9*n^2 + 12*n)/5, with equality iff n = (2/3)*(4^k-1) = A182512(k) for some k, i.e., n = 10101...10 in binary. - Conjectured by N. J. A. Sloane, Sep 09 2018, proved by M. F. Hasler, Sep 12 2018
From M. F. Hasler, Sep 12 2018: (Start)
Proof of N. J. A. Sloane's formula: For given (binary) length L(n) = floor(log_2(n)+1), the length of a(n) is maximal, L(a(n)) = 2*L(n), if and only if n's bits are alternating, i.e., n in A020988 (if even) or in A002450 (if odd).
For n = A020988(k) (= k times '10' in base 2) = (4^k - 1)*2/3, one has a(n) = A108020(k) (= k times '1100' in base 2) = (16^k - 1)*4/5. This yields a(n)/n = (4^k + 1)*6/5 = (n*9 + 12)/5, i.e., the given upper bound.
For n = A002450(k) = (4^k - 1)/3, one gets a(n) = A182512(k) = (16^k - 1)/5, whence a(n)/n = (4^k + 1)*3/5 = (n*9 + 6)/5, smaller than the bound.
If L(a(n)) < 2 L(n) - 1, then log_2(a(n)) < floor(log_2(a(n))+1) = L(a(n)) <= 2*L(n) - 2 = 2*floor(log_2(n)+1)-2 = 2*floor(log_2(n)) <= 2*log_2(n), whence a(n) < n^2.
It remains to consider the case L(a(n)) = 2 L(n) - 1. There are two possibilities:
If n = 10..._2, then n >= 2^(L(n)-1) and a(n) = 1100..._2 < 1101_2 * 2^(L(a(n))-4) = 13*2^(2*L(n)-5), so a(n)/n^2 < 13*2^(-5+2) = 13/8 = 1.625 < 9/5 = 1.8.
If n = 11..._2, then n >= 3*2^(L(n)-2) and a(n) = 111..._2 < 2^L(a(n)) = 2^(2*L(n)-1), so a(n)/n^2 < 2^(-1+4)/9 = 8/9 < 1 < 9/5.
This shows that a(n)/n^2 <= 9/5 + 12/(5*n) always holds, with equality iff n is in A020988; and a(n)/n^2 < 13/8 if n is not in A020988 or A002450. (End)
From M. F. Hasler, Sep 10 2018: (Start)
Right inverse of A318921: A318921 o A175046 = id (= A001477).
a(A020988(k)) = A108020(k); a(A002450(k)) = A182512(k); a(A000225(k)) = A000225(k+1) (achieves the lower bound a(n) >= 2n + 1) for all k >= 0. (End)
From David A. Corneth, Sep 20 2018: (Start)
a(4*k) = 2*a(2*k).
a(4*k+1) = 4*a(2*k) + 3.
a(4*k+2) = 4*a(2*k+1).
a(4*k+3) = 2*a(2*k+1) + 1. (End)

Extensions

Extended by Ray Chandler, Dec 18 2009

A320037 Write n in binary, then modify each run of 0's by appending one 1, and modify each run of 1's by appending one 0. a(n) is the decimal equivalent of the result.

Original entry on oeis.org

2, 9, 6, 17, 38, 25, 14, 33, 70, 153, 78, 49, 102, 57, 30, 65, 134, 281, 142, 305, 614, 313, 158, 97, 198, 409, 206, 113, 230, 121, 62, 129, 262, 537, 270, 561, 1126, 569, 286, 609, 1222, 2457, 1230, 625, 1254, 633, 318, 193, 390, 793, 398, 817, 1638, 825, 414
Offset: 1

Views

Author

Chai Wah Wu, Oct 04 2018

Keywords

Comments

A variation of A175046. Indices of record values are given by A319423.
From Chai Wah Wu, Nov 21 2018: (Start)
Let f(k) = Sum_{i=2^k..2^(k+1)-1} a(i), i.e., the sum ranges over all numbers with a (k+1)-bit binary expansion. Thus f(0) = a(1) = 2 and f(1) = a(2) + a(3) = 15.
Then f(k) = 16*6^(k-1) - 2^(k-1) for k > 0.
Proof: looking at the last 2 bits of n, it is easy to see that a(4n) = 2a(2n)-1, a(4n+1) = 4a(2n)+2, a(4n+2) = 4a(2n+1)+1 and a(4n+3) = 2a(2n+1)+2. By summing over the recurrence relations for a(n), we get f(k+2) = Sum_{i=2^k..2^(k+1)-1} (f(4i) + f(4i+1) + f(4i+2) + f(4i+3)) = Sum_{i=2^k..2^(k+1)-1} (6a(2i) + 6a(2i+1) + 4) = 6*f(k+1) + 2^(k+2). Solving this first order recurrence relation with the initial condition f(1) = 15 shows that f(k) = 16*6^(k-1) - 2^(k-1) for k > 0.
(End)

Examples

			6 in binary is 110. Modify each run by appending the opposite digit to get 11001, which is 25 in decimal. So a(6) = 25.
		

Crossrefs

Programs

  • Python
    from re import split
    def A320037(n):
        return int(''.join(d+'0' if '1' in d else d+'1' for d in split('(0+)|(1+)',bin(n)[2:]) if d != '' and d != None),2)

Formula

a(4n) = 2a(2n)-1, a(4n+1) = 4a(2n)+2, a(4n+2) = 4a(2n+1)+1 and a(4n+3) = 2a(2n+1)+2. - Chai Wah Wu, Nov 21 2018

A320038 Write n in binary, then modify each run of 0's by prepending one 1, and modify each run of 1's by prepending one 0. a(n) is the decimal equivalent of the result.

Original entry on oeis.org

1, 6, 3, 12, 25, 14, 7, 24, 49, 102, 51, 28, 57, 30, 15, 48, 97, 198, 99, 204, 409, 206, 103, 56, 113, 230, 115, 60, 121, 62, 31, 96, 193, 390, 195, 396, 793, 398, 199, 408, 817, 1638, 819, 412, 825, 414, 207, 112, 225, 454, 227, 460, 921, 462, 231, 120, 241
Offset: 1

Views

Author

Chai Wah Wu, Oct 04 2018

Keywords

Comments

A variation of A175046. Indices of record values are given by A319423.
From Chai Wah Wu, Nov 25 2018: (Start)
Let f(k) = Sum_{i=2^k..2^(k+1)-1} a(i), i.e., the sum ranges over all numbers with a (k+1)-bit binary expansion. Thus f(0) = a(1) = 1 and f(1) = a(2) + a(3) = 9.
Then f(k) = 10*6^(k-1) - 2^(k-1) for k > 0.
Proof: looking at the last 2 bits of n, it is easy to see that a(4n) = 2*a(2n), a(4n+1) = 4*a(2n)+1, a(4n+2) = 4*a(2n+1)+2 and a(4n+3) = 2*a(2n+1)+1. By summing over the recurrence relations for a(n), we get f(k+2) = Sum_{i=2^k..2^(k+1)-1} (f(4i) + f(4i+1) + f(4i+2) + f(4i+3)) = Sum_{i=2^k..2^(k+1)-1} (6a(2i) + 6a(2i+1) + 4) = 6*f(k+1) + 2^(k+2). Solving this first-order recurrence relation with the initial condition f(1) = 9 shows that f(k) = 10*6^(k-1) - 2^(k-1) for k > 0.
(End)

Examples

			6 in binary is 110. Modify each run by prepending the opposite digit to get 01110, which is 14 in decimal. So a(6) = 14.
		

Crossrefs

Programs

  • Mathematica
    a[n_] := Split[IntegerDigits[n, 2]] /. {a0:{(0)...} :> Prepend[a0, 1], a1:{(1)...} :> Prepend[a1, 0]} // Flatten // FromDigits[#, 2]&;
    Array[a, 60] (* Jean-François Alcover, Dec 02 2018 *)
  • Python
    from re import split
    def A320038(n):
        return int(''.join('0'+d if '1' in d else '1'+d for d in split('(0+)|(1+)',bin(n)[2:]) if d != '' and d != None),2)

Formula

a(n) = floor(A175046(n)/2).
a(4n) = 2*a(2n), a(4n+1) = 4*a(2n)+1, a(4n+2) = 4*a(2n+1)+2 and a(4n+3) = 2*a(2n+1)+1. - Chai Wah Wu, Nov 25 2018

A319422 Records in A175046.

Original entry on oeis.org

3, 12, 24, 51, 99, 204, 396, 408, 819, 1587, 1635, 3276, 6348, 6540, 6552, 13107, 25395, 26163, 26211, 52428, 101580, 104652, 104844, 104856, 209715, 406323, 418611, 419379, 419427, 838860, 1625292, 1674444, 1677516, 1677708, 1677720, 3355443, 6501171
Offset: 1

Views

Author

N. J. A. Sloane, Sep 23 2018

Keywords

Comments

a(n) in binary is either an alternating string of 11's and 00's, or exactly one of the 00's is replaced by 000 (see A319423). - Chai Wah Wu, Oct 04 2018

Crossrefs

Cf. A175046, A319423, A319424 (written in binary).

Programs

  • Mathematica
    b[n_] := (Append[#, #[[1]]]& /@ Split[IntegerDigits[n, 2]]) // Flatten // FromDigits[#, 2]&;
    Reap[For[rec = 0; k = 1, k < 3000, k++, bk = b[k]; If[bk > rec, rec = bk; Sow[rec]]]][[2, 1]] (* Jean-François Alcover, Nov 12 2018 *)

A319424 Records in A175046 (but written in base 2).

Original entry on oeis.org

11, 1100, 11000, 110011, 1100011, 11001100, 110001100, 110011000, 1100110011, 11000110011, 11001100011, 110011001100, 1100011001100, 1100110001100, 1100110011000, 11001100110011, 110001100110011, 110011000110011, 110011001100011, 1100110011001100, 11000110011001100, 11001100011001100, 11001100110001100, 11001100110011000, 110011001100110011, 1100011001100110011
Offset: 1

Views

Author

N. J. A. Sloane, Sep 23 2018

Keywords

Comments

More terms than usual are given in order to display the pattern.
Conjecture. a(n) is either an alternating string of 11's and 00's, or exactly one of the 00's is replaced by 000.
Conjecture is true (see A319423). - Chai Wah Wu, Oct 04 2018

Crossrefs

A320039 Write n in binary, then modify each run of 0's and each run of 1's by appending a 1. a(n) is the decimal equivalent of the result.

Original entry on oeis.org

3, 13, 7, 25, 55, 29, 15, 49, 103, 221, 111, 57, 119, 61, 31, 97, 199, 413, 207, 441, 887, 445, 223, 113, 231, 477, 239, 121, 247, 125, 63, 193, 391, 797, 399, 825, 1655, 829, 415, 881, 1767, 3549, 1775, 889, 1783, 893, 447, 225, 455, 925, 463, 953, 1911, 957
Offset: 1

Views

Author

Chai Wah Wu, Oct 05 2018

Keywords

Comments

A variation of A175046. Indices of record values are given by A319423.
From Chai Wah Wu, Nov 21 2018: (Start)
Let f(k) = Sum_{i=2^k..2^(k+1)-1} a(i), i.e., the sum ranges over all numbers with a (k+1)-bit binary expansion. Thus f(0) = a(1) = 3 and f(1) = a(2) + a(3) = 20.
Then f(k) = 21*6^(k-1) - 2^(k-1) for k >= 0.
Proof: the equation for f is true for k = 0. Looking at the last 2 bits of n, it is easy to see that a(4n) = 2*a(2n)-1, a(4n+1) = 4*a(2n)+3, a(4n+2) = 4*a(2n+1)+1 and a(4n+3) = 2*a(2n+1)+1. By summing over the recurrence relations for a(n), we get f(k+2) = Sum_{i=2^k..2^(k+1)-1} (f(4i) + f(4i+1) + f(4i+2) + f(4i+3)) = Sum_{i=2^k..2^(k+1)-1} (6a(2i) + 6a(2i+1) + 4) = 6*f(k+1) + 2^(k+2). Solving this first-order recurrence relation with the initial condition f(1) = 20 shows that f(k) = 21*6^(k-1) - 2^(k-1) for k > 0.
(End)

Examples

			6 in binary is 110. Modify each run by appending a 1 to get 11101, which is 29 in decimal. So a(6) = 29.
		

Crossrefs

Programs

  • Mathematica
    Array[FromDigits[Flatten@ Map[Append[#, 1] &, Split@ IntegerDigits[#, 2]], 2] &, 54] (* Michael De Vlieger, Nov 23 2018 *)
  • Python
    from re import split
    def A320039(n):
        return int(''.join(d+'1' for d in split('(0+)|(1+)',bin(n)[2:]) if d != '' and d != None),2)

Formula

a(4n) = 2*a(2n)-1, a(4n+1) = 4*a(2n)+3, a(4n+2) = 4*a(2n+1)+1 and a(4n+3) = 2*a(2n+1)+1. - Chai Wah Wu, Nov 21 2018

A320261 Write n in binary, then modify each run of 0's and each run of 1's by prepending a 1. a(n) is the decimal equivalent of the result.

Original entry on oeis.org

3, 14, 7, 28, 59, 30, 15, 56, 115, 238, 119, 60, 123, 62, 31, 112, 227, 462, 231, 476, 955, 478, 239, 120, 243, 494, 247, 124, 251, 126, 63, 224, 451, 910, 455, 924, 1851, 926, 463, 952, 1907, 3822, 1911, 956, 1915, 958, 479, 240, 483, 974, 487, 988, 1979, 990
Offset: 1

Views

Author

Chai Wah Wu, Oct 08 2018

Keywords

Comments

A variation of A175046. Indices of record values are given by A319423.
From Chai Wah Wu, Nov 25 2018 : (Start)
Let f(k) = Sum_{i=2^k..2^(k+1)-1} a(i), i.e., the sum ranges over all numbers with a (k+1)-bit binary expansion. Thus f(0) = a(1) = 3 and f(1) = a(2) + a(3) = 21, and f(2) = a(4)+a(5)+a(6)+a(7) = 132.
Then f(k) = 135*6^(k-2) - 3*2^(k-2) for k >= 0.
Proof: the formula is true for k = 0. Looking at the last 2 bits of n, it is easy to see that a(4n) = 2*a(2n), a(4n+1) = 4*a(2n)+3, a(4n+2) = 4*a(2n+1)+2 and a(4n+3) = 2*a(2n+1)+1. By summing over the recurrence relations for a(n), we get f(k+2) = Sum_{i=2^k..2^(k+1)-1} (f(4i) + f(4i+1) + f(4i+2) + f(4i+3)) = Sum_{i=2^k..2^(k+1)-1} (6a(2i) + 6a(2i+1) + 6) = 6*f(k+1) + 3*2^(k+1). Solving this first-order recurrence relation with the initial condition f(1) = 21 shows that f(k) = 135*6^(k-2) - 3*2^(k-2) for k > 0.
(End)

Examples

			6 in binary is 110. Modify each run by prepending a 1 to get 11110, which is 30 in decimal. So a(6) = 30.
		

Crossrefs

Programs

  • Mathematica
    Table[FromDigits[Flatten[Join[{1},#]&/@Split[IntegerDigits[n,2]]],2],{n,60}] (* Harvey P. Dale, Apr 26 2019 *)
  • Python
    from re import split
    def A320261(n):
        return int(''.join('1'+d for d in split('(0+)|(1+)',bin(n)[2:]) if d != '' and d != None),2)

Formula

a(4n) = 2*a(2n), a(4n+1) = 4*a(2n)+3, a(4n+2) = 4*a(2n+1)+2 and a(4n+3) = 2*a(2n+1)+1. - Chai Wah Wu, Nov 25 2018

A320262 Write n in binary, then modify each run of 0's and each run of 1's by appending a 0. a(n) is the decimal equivalent of the result.

Original entry on oeis.org

2, 8, 6, 16, 34, 24, 14, 32, 66, 136, 70, 48, 98, 56, 30, 64, 130, 264, 134, 272, 546, 280, 142, 96, 194, 392, 198, 112, 226, 120, 62, 128, 258, 520, 262, 528, 1058, 536, 270, 544, 1090, 2184, 1094, 560, 1122, 568, 286, 192, 386, 776, 390, 784, 1570, 792, 398
Offset: 1

Views

Author

Chai Wah Wu, Oct 08 2018

Keywords

Comments

A variation of A175046. Indices of record values are given by A319423.
From Chai Wah Wu, Nov 21 2018: (Start)
Let f(k) = Sum_{i=2^k..2^(k+1)-1} a(i), i.e., the sum ranges over all numbers with a (k+1)-bit binary expansion. Thus f(0) = a(1) = 2 and f(1) = a(2) + a(3) = 14.
Then f(k) = 15*6^(k-1) - 2^(k-1) for k >= 0.
Proof: the equation for f is true for k = 0. Looking at the last 2 bits of n, it is easy to see that a(4n) = 2*a(2n), a(4n+1) = 4*a(2n)+2, a(4n+2) = 4*a(2n+1) and a(4n+3) = 2*a(2n+1)+2. By summing over the recurrence relations for a(n), we get f(k+2) = Sum_{i=2^k..2^(k+1)-1} (f(4i) + f(4i+1) + f(4i+2) + f(4i+3)) = Sum_{i=2^k..2^(k+1)-1} (6a(2i) + 6a(2i+1) + 4) = 6*f(k+1) + 2^(k+2). Solving this first-order recurrence relation with the initial condition f(1) = 14 shows that f(k) = 15*6^(k-1) - 2^(k-1) for k > 0.
(End)

Examples

			6 in binary is 110. Modify each run by appending a 0 to get 11000, which is 24 in decimal. So a(6) = 24.
		

Crossrefs

Programs

  • Mathematica
    Array[FromDigits[Flatten@ Map[Append[#, 0] &, Split@ IntegerDigits[#, 2]], 2] &, 55] (* Michael De Vlieger, Nov 23 2018 *)
  • Python
    from re import split
    def A320262(n):
        return int(''.join(d+'0' for d in split('(0+)|(1+)',bin(n)[2:]) if d != '' and d != None),2)

Formula

a(n) = 2*A320263(n).
a(4n) = 2*a(2n), a(4n+1) = 4*a(2n)+2, a(4n+2) = 4*a(2n+1) and a(4n+3) = 2*a(2n+1)+2. - Chai Wah Wu, Nov 21 2018

A320263 Write n in binary, then modify each run of 0's and each run of 1's by prepending a 0. a(n) is the decimal equivalent of the result.

Original entry on oeis.org

1, 4, 3, 8, 17, 12, 7, 16, 33, 68, 35, 24, 49, 28, 15, 32, 65, 132, 67, 136, 273, 140, 71, 48, 97, 196, 99, 56, 113, 60, 31, 64, 129, 260, 131, 264, 529, 268, 135, 272, 545, 1092, 547, 280, 561, 284, 143, 96, 193, 388, 195, 392, 785, 396, 199, 112, 225, 452, 227
Offset: 1

Views

Author

Chai Wah Wu, Oct 08 2018

Keywords

Comments

A variation of A175046. Indices of record values are given by A319423.

Examples

			6 in binary is 110. Modify each run by prepending a 0 to get 01100, which is 12 in decimal. So a(6) = 12.
		

Crossrefs

Programs

  • Python
    from re import split
    def A320263(n):
        return int(''.join('0'+d for d in split('(0+)|(1+)',bin(n)[2:]) if d != '' and d != None),2)

Formula

a(n) = A320262(n)/2.
Showing 1-9 of 9 results.