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

A263017 n is the a(n)-th positive integer having its binary weight.

Original entry on oeis.org

1, 2, 1, 3, 2, 3, 1, 4, 4, 5, 2, 6, 3, 4, 1, 5, 7, 8, 5, 9, 6, 7, 2, 10, 8, 9, 3, 10, 4, 5, 1, 6, 11, 12, 11, 13, 12, 13, 6, 14, 14, 15, 7, 16, 8, 9, 2, 15, 17, 18, 10, 19, 11, 12, 3, 20, 13, 14, 4, 15, 5, 6, 1, 7, 16, 17, 21, 18, 22, 23, 16, 19, 24, 25, 17
Offset: 1

Views

Author

Paul Tek, Oct 07 2015

Keywords

Comments

Binary weight is given by A000120.
a(2^k) = k+1 for any k>=0.
a(2^k-1) = 1 for any k>0.
a(A057168(k)) = a(k)+1 for any k>0.
a(A036563(k+1)) = k for any k>0.
Ordinal transform of A000120. - Alois P. Heinz, Dec 23 2018

Examples

			The numbers with binary weight 3 are: 7, 11, 13, 14, 19, ...
Hence: a(7)=1, a(11)=2, a(13)=3, a(14)=4, a(19)=5, ...
And more generally: a(A014311(k))=k for any k>0.
		

Crossrefs

Programs

  • Haskell
    import Data.IntMap (empty, findWithDefault, insert)
    a263017 n = a263017_list !! (n-1)
    a263017_list = f 1 empty where
       f x m = y : f (x + 1) (insert h (y + 1) m) where
               y = findWithDefault 1 h m
               h = a000120 x
    -- Reinhard Zumkeller, Oct 09 2015
    
  • Maple
    a:= proc() option remember; local a, b, t; b, a:=
          proc() 0 end, proc(n) option remember; a(n-1);
            t:= add(i, i=convert(n, base, 2)); b(t):= b(t)+1
          end; a(0):=0; a
        end():
    seq(a(n), n=1..120);  # Alois P. Heinz, Dec 23 2018
  • Perl
    # See Links section.
    
  • Python
    from math import comb
    def A263017(n):
        c, k = 1, 0
        for i,j in enumerate(bin(n)[-1:1:-1]):
            if j == '1':
                k += 1
                c += comb(i,k)
        return c # Chai Wah Wu, Mar 01 2023

Formula

a(n) = 1 + A068076(n). - Antti Karttunen, May 22 2017

A067587 Inverse of A066884 considered as a permutation of the positive integers.

Original entry on oeis.org

1, 3, 2, 6, 5, 9, 4, 10, 14, 20, 8, 27, 13, 19, 7, 15, 35, 44, 26, 54, 34, 43, 12, 65, 53, 64, 18, 76, 25, 33, 11, 21, 77, 90, 89, 104, 103, 118, 42, 119, 134, 151, 52, 169, 63, 75, 17, 135, 188, 208, 88, 229, 102, 117, 24, 251, 133, 150, 32, 168, 41, 51, 16, 28, 152
Offset: 1

Views

Author

Jared Ricks (jaredricks(AT)yahoo.com), Jan 31 2002

Keywords

Crossrefs

Programs

  • Mathematica
    w[n_] := Plus@@IntegerDigits[n, 2]; p[n_] := Plus@@MapThread[Binomial, {Flatten[Position[Reverse[IntegerDigits[n, 2]], 1]]-1, Range[w[n]]}]; a[n_] := Binomial[w[n]+p[n], 2]+p[n]+1
  • PARI
    a(n)=my(w=hammingweight(n), p=sum(i=1, n-1, hammingweight(i)==w)); binomial(w+p, 2) + p + 1 \\ Jianing Song, Aug 06 2022
    
  • Perl
    foreach(1..10_000){$i=eval join "+", split //, sprintf "%b", $; $j=$r[$i]++; print "$ ",$j+1+($i+$j)*($i+$j-1)/2,"\n"} # Ivan Neretin, Mar 02 2016
    
  • Python
    from math import comb
    def A067587(n):
        c, k = 0, 0
        for i,j in enumerate(bin(n)[-1:1:-1]):
            if j == '1':
                k += 1
                c += comb(i,k)
        return comb(n.bit_count()+c,2)+c+1 # Chai Wah Wu, Mar 02 2023

Formula

Let w(n) = A000120(n) be the 'weight' of n; i.e. the number of 1's in the binary expansion of n. Let p(n) = A068076(n) be the number of positive integers < n with the same weight as n. Then a(n) = binomial(w(n)+p(n),2) + p(n) + 1.

Extensions

Edited by Dean Hickerson, Feb 16 2002
Offset changed to 1 by Ivan Neretin, Mar 02 2016

A079071 Number of numbers < n whose binary representation has the same number of 0's and 1's as n does.

Original entry on oeis.org

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

Views

Author

Reinhard Zumkeller, Dec 21 2002

Keywords

Crossrefs

Programs

  • Maple
    f:= n-> (x-> (t-> t*(t+1)/2+x[2])(x[1]+x[2]))(add(
        `if`(i=0, [1, 0], [0, 1]), i=convert(n, base, 2))):
    b:= proc(n) b(n):= b(n-1)+x^f(n) end: b(-1):=0:
    a:= n-> coeff(b(n-1), x, f(n)):
    seq(a(n), n=0..150);  # Alois P. Heinz, Feb 08 2018
  • Mathematica
    a[n_] := Count[Range[n-1], k_ /; DigitCount[n, 2] == DigitCount[k, 2]];
    Table[a[n], {n, 0, 104}] (* Jean-François Alcover, Feb 13 2018 *)

A079070 Number of numbers < n having in binary representation the same number of 0's as n.

Original entry on oeis.org

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

Views

Author

Reinhard Zumkeller, Dec 21 2002

Keywords

Examples

			n = 12 -> '1100': A023416(12) = 2 therefore a(12) = #{4 ->'100', 9 ->'1001', 10 ->'1010'} = 3.
n = 13 -> '1101': A023416(13) = 1 therefore a(13) = #{2 ->'10', 5 ->'101', 6 ->'110', 11 ->'1011'} = 4.
		

Crossrefs

Programs

Formula

a(n) = #{m : m < n and A023416(m) = A023416(n)}.
a(2^k - 1) = k - 1; a(2^k) = 0; a(2^k + 1) = 1.

A079073 Sum of numbers < n having in binary representation the same number of 1's as n.

Original entry on oeis.org

0, 0, 1, 0, 3, 3, 8, 0, 7, 14, 23, 7, 33, 18, 31, 0, 15, 45, 62, 45, 80, 64, 85, 15, 100, 107, 132, 38, 158, 65, 94, 0, 31, 124, 157, 186, 191, 221, 258, 124, 227, 296, 337, 163, 379, 206, 251, 31, 267, 423, 472, 297, 522, 348, 401, 78, 574, 455, 512, 133, 570, 192, 253, 0, 63
Offset: 0

Views

Author

Reinhard Zumkeller, Dec 21 2002

Keywords

Crossrefs

Programs

  • Maple
    f:= n-> add(i, i=convert(n, base, 2)):
    b:= proc(n) b(n):= b(n-1)+n*x^f(n) end: b(-1):=0:
    a:= n-> coeff(b(n-1), x, f(n)):
    seq(a(n), n=0..150);  # Alois P. Heinz, Feb 08 2018
  • Mathematica
    a[n_] := Module[{dc = DigitCount[n, 2, 1]}, Select[Range[n-1], DigitCount[#, 2, 1] == dc&] // Total];
    a /@ Range[0, 100] (* Jean-François Alcover, Nov 07 2020 *)
  • PARI
    a(n) = my(s=hammingweight(n)); sum(k=1, n-1, if (s==hammingweight(k), k)); \\ Michel Marcus, Nov 07 2020

A356419 Inverse of A067576 considered as a permutation of the positive integers.

Original entry on oeis.org

1, 2, 3, 4, 5, 8, 6, 7, 12, 17, 9, 23, 13, 18, 10, 11, 30, 38, 24, 47, 31, 39, 14, 57, 48, 58, 19, 69, 25, 32, 15, 16, 68, 80, 81, 93, 94, 108, 40, 107, 123, 139, 49, 156, 59, 70, 20, 122, 174, 193, 82, 213, 95, 109, 26, 234, 124, 140, 33, 157, 41, 50, 21, 22, 138, 155, 256
Offset: 1

Views

Author

Jianing Song, Aug 06 2022

Keywords

Examples

			A067576(12) = 9, so a(9) = 12.
		

Crossrefs

Programs

  • PARI
    a(n)=my(w=hammingweight(n), p=sum(i=1, n-1, hammingweight(i)==w)); binomial(w+p+1, 2) - p
    
  • Python
    from math import comb
    def A356419(n):
        c, k = 0, 0
        for i,j in enumerate(bin(n)[-1:1:-1]):
            if j == '1':
                k += 1
                c += comb(i,k)
        return comb(n.bit_count()+c+1,2)-c # Chai Wah Wu, Mar 02 2023

Formula

Let w(n) = A000120(n) be the Hamming weight of n, p(n) = A068076(n), then a(n) = binomial(w(n)+p(n)+1, 2) - p(n).

A361079 Number of integers in [n .. 2n-1] having the same binary weight as n.

Original entry on oeis.org

0, 1, 1, 2, 1, 3, 3, 3, 1, 4, 4, 5, 4, 6, 6, 4, 1, 5, 5, 8, 5, 9, 9, 7, 5, 10, 10, 9, 10, 10, 10, 5, 1, 6, 6, 12, 6, 13, 13, 13, 6, 14, 14, 15, 14, 16, 16, 9, 6, 15, 15, 18, 15, 19, 19, 12, 15, 20, 20, 14, 20, 15, 15, 6, 1, 7, 7, 17, 7, 18, 18, 23, 7, 19, 19
Offset: 0

Views

Author

Alois P. Heinz, Mar 01 2023

Keywords

Comments

Or number of steps it takes to double n, where each step goes to the next larger integer with the same binary weight.

Examples

			a(9) = 4: 9 -> 10 -> 12 -> 17 -> 18 or in binary: 1001_2 -> 1010_2 -> 1100_2 -> 10001_2 -> 10010_2.
		

Crossrefs

Programs

  • Maple
    b:= proc(n) option remember; uses Bits; local c, l, k;
          c, l:= 0, [Split(n)[], 0];
          for k while l[k]<>1 or l[k+1]<>0 do c:=c+l[k] od;
          Join([1$c, 0$k-c, 1, l[k+2..-1][]])
        end:
    a:= proc(n) option remember; local i, m, t; m, t:=n, 2*n;
          for i from 0 while m<>t do m:= b(m) od; i
        end:
    seq(a(n), n=0..100);
  • Mathematica
    f[n_] := f[n] = DigitCount[n, 2, 1]; a[n_] := Count[ Array[f, n, n], f[n]]; Array[a, 75, 0] (* Robert G. Wilson v, Mar 15 2023 *)
  • PARI
    a(n) = my(w=hammingweight(n)); sum(k=n, 2*n-1, hammingweight(k) == w); \\ Michel Marcus, Mar 16 2023
  • Python
    from math import comb
    def A361079(n):
        c, k = 0, 1
        for i,j in enumerate(bin(n)[-1:1:-1]):
            if j == '1':
                c += comb(i+1,k)-comb(i,k)
                k += 1
        return c # Chai Wah Wu, Mar 01 2023
    

Formula

a(n) = |{ k in [n, 2n-1] : A000120(k) = A000120(n) }|.
((x-> A057168(x))^a(n))(n) = 2*n.
a(n) = A068076(2n) - A068076(n) = A263017(2n) - A263017(n).
a(n) = 1 <=> n in { A000079 }.
Showing 1-7 of 7 results.