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.

A036994 Numbers k with the property that reading from right to left in the binary expansion of k, the number of 1's always stays ahead of the number of 0's.

Original entry on oeis.org

1, 3, 7, 11, 15, 23, 27, 31, 39, 43, 47, 55, 59, 63, 79, 87, 91, 95, 103, 107, 111, 119, 123, 127, 143, 151, 155, 159, 167, 171, 175, 183, 187, 191, 207, 215, 219, 223, 231, 235, 239, 247, 251, 255, 287, 303, 311, 315, 319, 335, 343, 347, 351, 359, 363, 367
Offset: 1

Views

Author

Keywords

Comments

Even numbers can't appear in this sequence. - Alonso del Arte, Sep 21 2011

Crossrefs

Programs

  • Haskell
    a036994 n = a036994_list !! (n-1)
    a036994_list = filter ((p 0) . a030308_row) [1, 3 ..] where
       p ones []    = ones > 0
       p ones (0:bs) = ones > 1 && p (ones - 1) bs
       p ones (1:bs) = p (ones + 1) bs
    -- Reinhard Zumkeller, Aug 01 2013
    
  • Mathematica
    aheadOnesRLQ[n_Integer] := Module[{digits, len, flag = True, iter = 1, ones = 0, zeros = 0}, digits = Reverse[IntegerDigits[n, 2]]; len = Length[digits]; While[flag && iter < len, If[digits[[iter]] == 1, ones++, zeros++]; flag = ones > zeros; iter++]; flag]; Select[Range[1, 201, 2], aheadOnesRLQ] (* Alonso del Arte, Sep 21 2011 *)
    Select[Range[400],Min[Accumulate[Reverse[IntegerDigits[#,2]/. (0->-1)]]]> 0&] (* Harvey P. Dale, Apr 23 2016 *)
  • PARI
    ok(x)={if(x<1,return(0));my(c=logint(x,2),c0=0,c1=0);for(i=0,c,if(bittest(x,i),c1++,c0++);if(c1<=c0,return(0)));1} \\ for(n=1,367,if(ok(n),print1(n,", "))) - Ruud H.G. van Tol, Sep 14 2022
  • Python
    from itertools import count, islice
    def A036994_gen(startvalue=0): # generator of terms >= startvalue
        for n in count(max(startvalue,0)):
            s = bin(n)[2:]
            c, l = 0, len(s)
            for i in range(l):
                c += int(s[l-i-1])
                if 2*c <= i + 1:
                    break
            else:
                yield n
    A036994_list = list(islice(A036994_gen(),20)) # Chai Wah Wu, Dec 31 2021
    

Extensions

More terms from Erich Friedman