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 11 results. Next

A044813 Positive integers having distinct base-2 run lengths.

Original entry on oeis.org

1, 3, 4, 6, 7, 8, 14, 15, 16, 24, 28, 30, 31, 32, 35, 39, 48, 49, 55, 57, 59, 60, 62, 63, 64, 67, 79, 96, 97, 111, 112, 120, 121, 123, 124, 126, 127, 128, 131, 135, 143, 159, 192, 193, 223, 224, 225, 239, 241, 247, 248, 249, 251, 252, 254, 255, 256, 259, 263
Offset: 1

Views

Author

Keywords

Comments

A005811(a(n)) = A165413(a(n)). - Reinhard Zumkeller, Mar 02 2013
From Emeric Deutsch, Jan 25 2018: (Start)
Also, the indices of the compositions that have distinct parts. For the definition of the index of a composition see A298644. For example, 223 is in the sequence since its binary form is 11011111 and the composition [2,1,5] has distinct parts. 100 is not in the sequence since its binary form is 1100100 and the parts of the composition [2,2,1,2] are not distinct.
The command c(n) from the Maple program yields the composition having index n. (End)

Crossrefs

Programs

  • Haskell
    import Data.List (group, nub)
    a044813 n = a044813_list !! (n-1)
    a044813_list = filter p [1..] where
       p x = nub xs == xs where
             xs = map length $ group $ a030308_row x
    -- Reinhard Zumkeller, Mar 02 2013
    
  • Maple
    Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: A := {}: for n to 300 do if nops(convert(c(n), set)) = nops(c(n)) then A := `union`(A, {n}) else end if end do: A; # most of the Maple program is due to W. Edwin Clark. - Emeric Deutsch, Jan 25 2018
  • Mathematica
    f[n_] := Unequal@@Length/@Split[IntegerDigits[n,2]]; Select[Range[300],f] (* Ray Chandler, Oct 21 2011 *)
  • PARI
    is(n) = {
      my(v = 0, hist = vector(1 + logint(n+1, 2)));
      while(n != 0,
            v = valuation(n, 2); n >>= v; n++;
            hist[v+1]++; if (hist[v+1] >= 2, return(0));
            v = valuation(n, 2); n >>= v; n--;
            hist[v+1]++; if (hist[v+1] >= 2, return(0)));
      return(1);
    };
    seq(n) = {
      my(k = 1, top = 0, v = vector(n));
      while(top < n, if (is(k), v[top++] = k); k++);
      return(v);
    };
    seq(59) \\ Gheorghe Coserea, Nov 02 2015
    
  • Python
    from itertools import groupby
    def ok(n):
      runlengths = [len(list(g)) for k, g in groupby(bin(n)[2:])]
      return len(runlengths) == len(set(runlengths))
    print([i for i in range(1, 264) if ok(i)]) # Michael S. Branicky, Jan 04 2021

Formula

a(Sum_{k=0..n} A032020(k)) = 2^n, for n>1. - Gheorghe Coserea, May 30 2017

Extensions

Extended by Ray Chandler, Oct 21 2011

A001196 Double-bitters: only even length runs in binary expansion.

Original entry on oeis.org

0, 3, 12, 15, 48, 51, 60, 63, 192, 195, 204, 207, 240, 243, 252, 255, 768, 771, 780, 783, 816, 819, 828, 831, 960, 963, 972, 975, 1008, 1011, 1020, 1023, 3072, 3075, 3084, 3087, 3120, 3123, 3132, 3135, 3264, 3267, 3276, 3279, 3312, 3315, 3324, 3327, 3840, 3843
Offset: 0

Views

Author

N. J. A. Sloane, based on an email from Bart la Bastide (bart(AT)xs4all.nl)

Keywords

Comments

Numbers whose set of base 4 digits is {0,3}. - Ray Chandler, Aug 03 2004
n such that there exists a permutation p_1, ..., p_n of 1, ..., n such that i + p_i is a power of 4 for every i. - Ray Chandler, Aug 03 2004
The first 2^n terms of the sequence could be obtained using the Cantor-like process for the segment [0, 4^n-1]. E.g., for n=1 we have [0, {1, 2}, 3] such that numbers outside of braces are the first 2 terms of the sequence; for n=2 we have [0, {1, 2}, 3, {4, 5, 6, 7, 8, 9, 10, 11}, 12, {13, 14}, 15] such that the numbers outside of braces are the first 4 terms of the sequence, etc. - Vladimir Shevelev, Dec 17 2012
From Emeric Deutsch, Jan 26 2018: (Start)
Also, the indices of the compositions having only even parts. For the definition of the index of a composition, see A298644. For example, 195 is in the sequence since its binary form is 11000011 and the composition [2,4,2] has only even parts. 132 is not in the sequence since its binary form is 10000100 and the composition [1,4,1,2] also has odd parts.
The command c(n) from the Maple program yields the composition having index n. (End)
After the k-th step of generating the Koch snowflake curve, label the edges of the curve consecutively 0..3*4^k-1 starting from a vertex of the originating triangle. a(0), a(1), ... a(2^k-1) are the labels of the edges contained in one edge of the originating triangle. Add 4^k to each label to get the labels for the next edge of the triangle. Compare with A191108 in respect of the Sierpinski arrowhead curve. - Peter Munn, Aug 18 2019

Crossrefs

3 times the Moser-de Bruijn sequence A000695.
Two digits in other bases: A005823, A097252-A097262.
Digit duplication in other bases: A338086, A338754.
Main diagonal of A054238.
Cf. A191108.

Programs

  • C
    int a_next(int a_n) { int t = a_n << 1; return a_n ^ t ^ (t + 3); } /* Falk Hüffner, Jan 24 2022 */
  • Haskell
    a001196 n = if n == 0 then 0 else 4 * a001196 n' + 3 * b
                where (n',b) = divMod n 2
    -- Reinhard Zumkeller, Feb 21 2014
    
  • Maple
    Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: A := {}: for n to 3350 do if type(product(1+c(n)[j], j = 1 .. nops(c(n))), odd) = true then A := `union`(A, {n}) else  end if end do: A; # most of the Maple  program is due to W. Edwin Clark. - Emeric Deutsch, Jan 26 2018
    # second Maple program:
    a:= proc(n) option remember;
         `if`(n<2, 3*n, 4*a(iquo(n, 2, 'r'))+3*r)
        end:
    seq(a(n), n=0..100);  # Alois P. Heinz, Jan 24 2022
  • Mathematica
    fQ[n_] := Union@ Mod[Length@# & /@ Split@ IntegerDigits[n, 2], 2] == {0}; Select[ Range@ 10000, fQ] (* Or *)
    fQ[n_] := Union@ Join[IntegerDigits[n, 4], {0, 3}] == {0, 3}; Select[ Range@ 10000, fQ] (* Robert G. Wilson v, Dec 24 2012 *)
  • PARI
    a(n) = 3*fromdigits(binary(n),4); \\ Kevin Ryde, Nov 07 2020
    
  • Python
    def inA001196(n):
        while n != 0:
            if n%4 == 1 or n%4 == 2:
                return 0
            n = n//4
        return 1
    n, a = 0, 0
    while n < 20:
        if inA001196(a):
            print(n,a)
            n = n+1
        a = a+1 # A.H.M. Smeets, Aug 19 2019
    
  • Python
    from itertools import groupby
    def ok2lb(n):
      if n == 0: return True  # by convention
      return all(len(list(g))%2 == 0 for k, g in groupby(bin(n)[2:]))
    print([i for i in range(3313) if ok2lb(i)]) # Michael S. Branicky, Jan 04 2021
    
  • Python
    def A001196(n): return 3*int(bin(n)[2:],4) # Chai Wah Wu, Aug 21 2023
    

Formula

a(2n) = 4*a(n), a(2n+1) = 4*a(n) + 3.
a(n) = 3 * A000695(n).
Sum_{n>=1} 1/a(n) = 0.628725478158702414849086504025451177643560169366348272891020450593453403709... (calculated using Baillie and Schmelzer's kempnerSums.nb, see Links). - Amiram Eldar, Feb 12 2022

A140690 A positive integer n is included if n written in binary can be subdivided into a number of runs all of equal-length, the first run from the left consisting of all 1's, the next run consisting of all 0's, the next run consisting of all 1's, the next run consisting of all 0's, etc.

Original entry on oeis.org

1, 2, 3, 5, 7, 10, 12, 15, 21, 31, 42, 51, 56, 63, 85, 127, 170, 204, 240, 255, 341, 455, 511, 682, 819, 992, 1023, 1365, 2047, 2730, 3276, 3640, 3855, 4032, 4095, 5461, 8191, 10922, 13107, 16256, 16383, 21845, 29127, 31775, 32767, 43690, 52428, 61680
Offset: 1

Views

Author

Leroy Quet, Jul 11 2008

Keywords

Comments

Also: numbers of the form (2^s-1)*[4^{s*(k+1)}-1]/(4^s-1) or 2^s(2^s-1)*[4^{s*(k+1)}-1]/(4^s-1), s>=1, k>=0. Subsequences are, with the possible exception of terms at n=0, A002450(n), A043291(n), A015565(2n), A093134(2n+1), A000225(n), A020522(n). [R. J. Mathar, Aug 04 2008]
From Emeric Deutsch, Jan 25 2018: (Start)
Also the indices of the compositions having equal parts.
We define the index of a composition to be the positive integer whose binary form has run-lengths (i.e. runs of 1's, runs of 0's, etc., from left to right) equal to the parts of the composition. Example: the composition [1,1,3,1] has index 46 since the binary form of 46 is 101110. The integer 992 is in the sequence since its binary form is 1111100000 and the composition [5,5] has equal parts. The integer 100 is not in the sequence since its binary form is 1100100 and the composition [2,2,1,2] does not have equal parts.
The command c(n) from the Maple program yields the composition having index n. (End)

Examples

			819 in binary is 1100110011. The runs of 0's and 1's are (11)(00)(11)(00)(11). Each run (alternating 1's and 0's) is the same length. So 819 is in the sequence.
		

Crossrefs

Programs

  • Haskell
    import Data.Set (singleton, deleteFindMin, insert)
    a140690 n = a140690_list !! (n-1)
    a140690_list = f $ singleton (1, 1, 2) where
       f s | k == 1 = m : f (insert (2*b-1, 1, 2*b) $ insert (b*m, k+1, b) s')
           | even k    = m : f (insert (b*m+b-1, k+1, b) s')
           | otherwise = m : f (insert (b*m, k+1, b) s')
           where ((m, k, b), s') = deleteFindMin s
    -- Reinhard Zumkeller, Feb 21 2014
  • Maple
    Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: A := {}: for n to 62000 do if nops(convert(c(n), set)) = 1 then A := `union`(A, {n}) else  end if end do: A; # most of the Maple program is due to W. Edwin Clark. - Emeric Deutsch, Jan 25 2018
  • Mathematica
    Select[Range[62000],Length[Union[Length/@Split[IntegerDigits[#,2]]]]==1&] (* Harvey P. Dale, Mar 22 2012 *)

Extensions

Terms beyond 42 from R. J. Mathar, Aug 04 2008

A063037 Numbers without 3 consecutive equal binary digits.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 18, 19, 20, 21, 22, 25, 26, 27, 36, 37, 38, 41, 42, 43, 44, 45, 50, 51, 52, 53, 54, 73, 74, 75, 76, 77, 82, 83, 84, 85, 86, 89, 90, 91, 100, 101, 102, 105, 106, 107, 108, 109, 146, 147, 148, 149, 150, 153, 154, 155, 164, 165, 166
Offset: 1

Views

Author

Lior Manor, Jul 05 2001

Keywords

Comments

Complement of A136037; intersection of A003796 and A003726. - Reinhard Zumkeller, Dec 11 2007
From Emeric Deutsch, Jan 27 2018: (Start)
Also 0 together with the indices of the compositions that have no parts larger than 2. For the definition of the index of a composition see A298644.
For example, 105 is in the sequence since its binary form is 1101001 and the composition [2,1,1,2,1] has no parts larger than 2.
On the other hand, 132 is not in the sequence since its binary form is 10000100 and the composition [1,4,1,2] has a part larger than 2.
The command c(n) from the Maple program yields the composition having index n. (End)
The sequence contains A000045(n+1) positive terms with binary length n. - Rémy Sigrist, Sep 30 2022

Examples

			The binary representation of 9 (1001) has no 3 consecutive equal digits.
		

Crossrefs

Programs

  • Maple
    isA063037 := proc(n)
        local bdgs,rep,d,i ;
        if n = 0 then
            return true;
        end if;
        bdgs := convert(n,base,2) ;
        rep := 1;
        d := op(1,bdgs) ;
        for i from 2 to nops(bdgs) do
            if op(i,bdgs) = op(i-1,bdgs) then
                rep := rep+1 ;
            else
                rep :=1 ;
            end if ;
            if rep > 2 then
                return false;
            end if;
        end do:
        return true ;
    end proc:
    for n from 0 to 50 do
        if isA063037(n) then
            printf("%d,",n) ;
        end if;
    end do: # R. J. Mathar, Dec 18 2013
    # Second Maple program:
    Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: A := {0}: for n to 250 do if `subset`(convert(c(n), set), {1, 2}) then A := `union`(A, {n}) else end if end do: A; # most of this Maple program is due to W. Edwin Clark. - Emeric Deutsch, Jan 27 2018
  • Mathematica
    Select[Range[0, 168], AllTrue[Length /@ Split@ IntegerDigits[#, 2], # < 3 &] &] (* Michael De Vlieger, Aug 20 2017 *)
  • PARI
    { n=0; for (m=0, 10^9, x=m; t=1; b=2; while (x>0, d=x-2*(x\2); x\=2; if (d==b, c++; if (c==3, t=x=0), b=d; c=1)); if (t, write("b063037.txt", n++, " ", m); if (n==1000, break)) ) } \\ Harry J. Smith, Aug 16 2009
    
  • PARI
    a(n) = { n--; if (n<=1, return (n), my (s=1); for (i=1, oo, my (f=fibonacci(i+1)); if (nRémy Sigrist, Sep 30 2022
    
  • Python
    from itertools import count, islice
    def A063037_gen(startvalue=0): # generator of terms >= startvalue
        return filter(lambda n: not ('000' in (s:=bin(n)[2:]) or '111' in s), count(max(0,startvalue)))
    A063037_list = list(islice(A063037_gen(),20)) # Chai Wah Wu, Oct 04 2022

Formula

It appears (but has not yet been proved) that the terms of {a(n)} can be computed recursively as follows. Let {c(i)} be defined for i >= 4 by c(i) = 2c(i-1) + 1, if i is a multiple of 3, else c(i) = 2c(i-1) - 1, with c(4) = 1. I.e., {c(i)} = {1,1,3,5,9,19,37,73,147,...}, for i=4,5,6,... . Let a(1)=1, a(2)=2, a(3)=3. For n > 3, choose k so that F(k)-2 < n <= F(k+1)-2, where F(k) denotes the k-th Fibonacci number (A000045). Then a(n) = c(k) + 2a(F(k)-2) - a(2F(k)-n-3). This has been verified for n up to 1100. - John W. Layman, May 26 2009

Extensions

Missing "less than" sign supplied in the conjectured recurrence (thanks to Franklin T. Adams-Watters for pointing this out) by John W. Layman, Nov 09 2009

A044918 Positive integers whose base-2 run lengths form a palindrome.

Original entry on oeis.org

1, 2, 3, 5, 7, 9, 10, 12, 15, 17, 21, 27, 31, 33, 38, 42, 45, 51, 52, 56, 63, 65, 73, 85, 93, 99, 107, 119, 127, 129, 142, 150, 153, 165, 170, 178, 189, 195, 204, 212, 219, 231, 232, 240, 255, 257, 273, 297, 313, 325, 341, 365, 381
Offset: 1

Views

Author

Keywords

Comments

This sequence exactly contains those positive integers in A006995 (positive binary palindromes) together with the terms of A035928 (those positive integers n where reversing the order of the binary digits produces the binary complement of n). - Leroy Quet, Sep 14 2009
Also the indices of the compositions that are palindromic. For the definition of the index of a composition see A298644. For example, 93 is in the sequence since its binary form is 1011101 and the composition [1,1,3,1,1] is palindromic. On the other hand, 132 is not in the sequence since its binary form is 10000100 and the composition [1,4,1,2] is not palindromic. The command c(n) from the Maple program yields the composition having index n. - Emeric Deutsch, Jan 28 2018

Crossrefs

Cf. A006995, A035928. - Leroy Quet, Sep 14 2009
Cf. A298644, A101211. - Emeric Deutsch, Jan 28 2018

Programs

  • Maple
    Runs:=proc(L) local j,r,i,k:j:=1: r[j]:=L[1]: for i from 2 to nops(L) do if L[i]=L[i-1] then r[j]:=r[j], L[i] else j:=j+1: r[j]:=L[i] end if end do: [seq([r[k]],k=1..j)] end proc: RunLengths:=proc(L) map(nops,Runs(L)) end  proc: c:=proc(n) ListTools:-Reverse(convert(n,base,2)): RunLengths(`%`) end proc: A:={}: for n from 1 to 500 do crev(n):=[seq(c(n)[1+ nops(c(n))-j],j=1..nops(c(n)))] od:  for n from 1 to 500 do if c(n)=crev(n) then A:=A union {n} else fi od: A; # most of the Maple program is due to W. Edwin Clark. # Emeric Deutsch, Jan 28 2018
  • Mathematica
    Position[Array[Length /@ Split@ IntegerDigits[#, 2] &, 400], ? PalindromeQ, 1] // Flatten (* _Michael De Vlieger, Jan 28 2018 *)
  • PARI
    ispal(v) = {for(i=1, #v\2, if (v[i] != v[#v-i+1], return(0));); return(1);}
    isok(n) = {b = binary(n); lastb = b[1]; vrun = vector(1); vrun[1] = 1; for (i=2, #b, if (b[i] != lastb, vrun = concat(vrun, 1); lastb = b[i];, vrun[#vrun]++;)); return (ispal(vrun));} \\ Michel Marcus, Jul 10 2013

A280998 Numbers with a prime number of 1's in their binary reflected Gray code representation.

Original entry on oeis.org

2, 4, 5, 6, 8, 9, 11, 12, 13, 14, 16, 17, 19, 21, 23, 24, 25, 27, 28, 29, 30, 32, 33, 35, 37, 39, 41, 43, 45, 47, 48, 49, 51, 53, 55, 56, 57, 59, 60, 61, 62, 64, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 96, 97, 99, 101, 103
Offset: 1

Views

Author

Indranil Ghosh, Jan 12 2017

Keywords

Comments

From Emeric Deutsch, Jan 28 2018: (Start)
Also the indices of the compositions that have a prime number of parts. For the definition of the index of a composition see A298644.
For example, 27 is in the sequence since its binary form is 11011 and the composition [2,1,2] has 3 parts.
On the other hand, 58 is not in the sequence since its binary form is 111010 and the composition [3,1,1,1] has 4 parts.
The command c(n) from the Maple program yields the composition having index n. (End)

Examples

			27 is in the sequence because the binary reflected Gray code representation of 27 is 10110 which has 3 1's, and 3 is prime.
		

Crossrefs

Programs

  • Maple
    Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]:
    for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1:
    r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc:
    RunLengths := proc (L) map(nops, Runs(L)) end proc:
    c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc:
    A := {}: for n to 175 do if isprime(nops(c(n))) = true then A := `union`(A, {n}) else end if end do: A;
    # most of the program is due to W. Edwin Clark. # Emeric Deutsch, Jan 28 2018
  • Mathematica
    Select[Range[100], PrimeQ[DigitCount[BitXor[#, Floor[#/2]], 2, 1]] &] (* Amiram Eldar, May 01 2021 *)
  • PARI
    is(n)=isprime(hammingweight(bitxor(n, n>>1))) \\ Charles R Greathouse IV, Jan 12 2017

A226229 Numbers m such that all lengths of runs of digits in base 2 representation of m are primes.

Original entry on oeis.org

3, 7, 12, 24, 28, 31, 51, 56, 96, 99, 103, 115, 124, 127, 199, 204, 224, 227, 231, 248, 384, 387, 396, 408, 412, 415, 455, 460, 499, 508, 775, 792, 796, 799, 819, 824, 896, 899, 908, 920, 924, 927, 992, 995, 999, 1016, 1539, 1548, 1587, 1592, 1632, 1635, 1639, 1651, 1660
Offset: 1

Views

Author

Alex Ratushnyak, May 31 2013

Keywords

Comments

Intersection of A226227 and A226228.
From Emeric Deutsch, Jan 27 2018: (Start)
Also the indices of the compositions having only prime parts. For the definition of the index of a composition see A298644. For example, 387 is in the sequence since its binary form is 110000011 and the parts of the composition [2,5,2] are prime numbers. 540 is not in the sequence since its binary form is 1000011100 and not all the parts of the composition [1,4,3,2] are primes.
The command c(n) from the Maple program yields the composition having index n. (End)

Crossrefs

Programs

  • Haskell
    import Data.List (group, genericLength)
    a226229 n = a226229_list !! (n-1)
    a226229_list = filter
       (all (== 1) . map (a010051 . genericLength) . group . a030308_row) [1..]
    -- Reinhard Zumkeller, Jun 05 2013
  • Maple
    Runs := proc (L) local j, r, i, k: npr: j := 1; r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: npr := proc (s) local q, j: q := 0: for j to nops(s) do if isprime(s[j]) = true then q := q+1 else  end if end do end proc: A := {}: for n to 1661 do if npr(c(n)) = nops(c(n)) then A := `union`(A, {n}) else  end if end do: A; # most of the Maple program is due to W. Edwin Clark. # Emeric Deutsch, Jan 27 2018
  • Mathematica
    Select[Range@1660, And @@ PrimeQ[Length /@ Split@ IntegerDigits[#, 2]] &] (* Giovanni Resta, Jun 01 2013 *)

A160530 Positive integers that contain only odd-length runs of 0's and 1's in their binary expansion.

Original entry on oeis.org

1, 2, 5, 7, 8, 10, 14, 17, 21, 23, 29, 31, 32, 34, 40, 42, 46, 56, 58, 62, 65, 69, 71, 81, 85, 87, 93, 95, 113, 117, 119, 125, 127, 128, 130, 136, 138, 142, 160, 162, 168, 170, 174, 184, 186, 190, 224, 226, 232, 234, 238, 248, 250, 254, 257, 261, 263, 273, 277, 279
Offset: 1

Views

Author

Leroy Quet, May 17 2009

Keywords

Comments

Let the binary representation of n be thought of as a string of 0's and 1's. By a "run" of 0's or 1's, it is meant either a contiguous substring all of 0's bounded by 1's or the by the edge of the string, or a contiguous substring all of 1's bounded by 0's or the by the edge of the string.
Also, the indices of the compositions that have only odd parts. For the definition of the index of a composition see A298644. For example, 263 is in the sequence since its binary form is 100000111 and the composition [1,5,3] has only odd parts. 132 is not in the sequence since its binary form is 10000100 and the composition [1,4,1,2] also has even parts. The command c(n) from the Maple program yields the composition having index n. - Emeric Deutsch, Jan 26 2018
From Robert Israel, Jan 26 2018: (Start)
An even number n is in the sequence if and only if n = 2^k*m where k is odd and m is an odd number in the sequence.
An odd number n is in the sequence if and only if n = 2^k*(m+1)-1 where k is odd and m is 0 or an even number in the sequence. (End)

Crossrefs

Programs

  • Maple
    Runs := proc (L) local j, r, i, k: j := 1; r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: A := {}: for n to 280 do if type(product(c(n)[j], j = 1 .. nops(c(n))), odd) = true then A := `union`(A, {n}) else  end if end do: A; # most of the Maple program is due to W. Edwin Clark. - Emeric Deutsch, Jan 26 2018
    # Alternative:
    filter:= proc(n) option remember; local t;
    if n::even then
      t:= padic:-ordp(n,2);
      if t::even then return false fi;
      procname(n/2^t)
    else
      t:= padic:-ordp(n+1,2);
      if t::even then return false fi;
      procname((n+1)/2^t-1)
      fi
    end proc:
    filter(0):= true:
    select(filter, [$1..1000]); # Robert Israel, Jan 26 2018
  • Mathematica
    Select[Range[300],And@@OddQ/@Length/@Split[IntegerDigits[ #,2]]&] (* Ray Chandler, May 19 2009 *)
  • Python
    from itertools import groupby
    def ok(n): return all(len(list(g))%2 == 1 for k, g in groupby(bin(n)[2:]))
    print([i for i in range(1, 280) if ok(i)]) # Michael S. Branicky, Jan 04 2021

Extensions

Extended by Ray Chandler, May 19 2009

A165317 a(n) = the number of digits in the binary representation of n that each do not precede or follow a similarly valued digit.

Original entry on oeis.org

1, 2, 0, 1, 3, 1, 0, 1, 2, 4, 2, 0, 2, 1, 0, 1, 2, 3, 1, 3, 5, 3, 2, 0, 1, 3, 1, 0, 2, 1, 0, 1, 2, 3, 1, 2, 4, 2, 1, 3, 4, 6, 4, 2, 4, 3, 2, 0, 1, 2, 0, 2, 4, 2, 1, 0, 1, 3, 1, 0, 2, 1, 0, 1, 2, 3, 1, 2, 4, 2, 1, 2, 3, 5, 3, 1, 3, 2, 1, 3, 4, 5, 3, 5, 7, 5, 4, 2, 3, 5, 3, 2, 4, 3, 2, 0, 1, 2, 0, 1, 3, 1, 0, 2, 3
Offset: 1

Views

Author

Leroy Quet, Sep 14 2009

Keywords

Comments

A165316(n) + a(n) = the number of digits in the binary representation of n.
Also number of parts equal to 1 in the composition having index n. For the definition of the index of a composition see A298644. For example, a(18) = 3 since the binary form of 18 is (1)00(1)(0) which has 3 runs of length 1 (each placed between parentheses). The command c(n) from the Maple program yields the composition having index n. - Emeric Deutsch, Jan 29 2018

Examples

			184 in binary is 10111001. There are exactly three binary digits (the first and last 1's, and the leftmost 0) that are each not adjacent to a similar digit. So a(184) = 3.
		

Crossrefs

Programs

  • Maple
    Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: a := proc (n) local ct, j: ct := 0: for j to nops(c(n)) do if c(n)[j] = 1 then ct := ct+1 else end if end do: ct end proc: seq(a(n), n = 1 .. 105); # most of the Maple program is due to W. Edwin Clark. # Emeric Deutsch, Jan 29 2018
  • Python
    def a(n): return ((n^(n<<1))&(n^(n>>1))).bit_count() + ((n&3)==2)
    print([a(n) for n in range(1, 106)]) # Michael S. Branicky, May 12 2024

Extensions

Extended by Ray Chandler, Mar 13 2010

A044888 Numbers whose base-2 run lengths alternate: even, odd, even, ...

Original entry on oeis.org

3, 6, 15, 24, 27, 30, 54, 63, 96, 99, 111, 120, 123, 126, 198, 216, 219, 222, 246, 255, 384, 387, 399, 438, 447, 480, 483, 495, 504, 507, 510, 774, 792, 795, 798, 864, 867, 879, 888, 891, 894, 966, 984, 987, 990, 1014, 1023, 1536
Offset: 1

Views

Author

Keywords

Comments

From Emeric Deutsch, Jan 27 2018: (Start)
Also the indices of the compositions whose parts alternate: even, odd, even, ... . For the definition of the index of a composition see A298644.
For example, 99 is in the sequence since its binary form is 1100011 and the composition [2,3,2] has parts: even, odd, even. 100 is not in the sequence since its binary form is 1100100 and the composition [2,2,1,2] has parts even, even, odd, even. The command c(n) from the Maple program yields the composition having index n. (End)

Crossrefs

Programs

  • Maple
    Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: A := {}: for n to 1540 do if `and`(type(c(n)[1], even) = true, type(product(c(n)[j]-c(n)[j+1], j = 1 .. nops(c(n))-1), odd)) then A := `union`(A, {n}) else  end if end do: A; # most of the Maple program is due to W. Edwin Clark. # Emeric Deutsch, Jan 27 2018
  • Mathematica
    oeQ[n_]:=Module[{idsleb=Boole[EvenQ/@(Length/@Split[IntegerDigits[ n,2]])]},idsleb == PadRight[{},Length[idsleb],{1,0}]]; Select[ Range[ 1600],oeQ] (* Harvey P. Dale, Sep 04 2020 *)
  • Python
    from itertools import groupby
    def ok(n): return all(len(list(g))%2 == i%2 for i, (k, g) in enumerate(groupby(bin(n)[2:])))
    print([i for i in range(1, 1537) if ok(i)]) # Michael S. Branicky, Jan 04 2021
Showing 1-10 of 11 results. Next