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.

A246590 Even numbers whose odd part is of the form 4m+3; Numbers missing from A241816.

Original entry on oeis.org

6, 12, 14, 22, 24, 28, 30, 38, 44, 46, 48, 54, 56, 60, 62, 70, 76, 78, 86, 88, 92, 94, 96, 102, 108, 110, 112, 118, 120, 124, 126, 134, 140, 142, 150, 152, 156, 158, 166, 172, 174, 176, 182, 184, 188, 190, 192, 198, 204, 206, 214, 216, 220, 222, 224, 230, 236
Offset: 1

Views

Author

N. J. A. Sloane, Sep 03 2014

Keywords

Comments

Numbers with bit-0 in their binary representation zero, and whose least significant 1-bit is neighbored (to the left) by another 1-bit, in other words, all even terms of A091067. - Antti Karttunen, Feb 20 2015
The asymptotic density of this sequence is 1/4. - Amiram Eldar, Aug 31 2024

Crossrefs

Complement of A241816.
Cf. A091067.

Programs

  • Mathematica
    Select[2 * Range[120], Mod[# / 2^IntegerExponent[#, 2], 4] == 3 &] (* Amiram Eldar, Aug 31 2024 *)
  • PARI
    is(k) = !(k % 2) && (k >> valuation(k, 2)) % 4 == 3; \\ Amiram Eldar, Aug 31 2024

Formula

a(n) = 2*A091067(n). - Antti Karttunen, Feb 20 2015

Extensions

More terms from Alois P. Heinz, Sep 07 2014
New definition added to name by Antti Karttunen, Feb 20 2015

A055941 a(n) = Sum_{j=0..k-1} (i(j) - j) where n = Sum_{j=0..k-1} 2^i(j).

Original entry on oeis.org

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

Views

Author

Anno Siegel (siegel(AT)zrz.tu-berlin.de), Jul 18 2000

Keywords

Comments

Used to calculate number of subspaces of Zp^n where Zp is field of integers mod p.
Consider a square matrix A and call it special if (0) A is an upper triangular matrix, (1) a nonzero column of A has a 1 on the main diagonal and (2) if a row has a 1 on the main diagonal then this is the only nonzero element in that row.
If the diagonal of a special matrix is given (it can only contain 0's and 1's), many of the fields of A are determined by (0), (1) and (2). The number of fields that can be freely chosen while still satisfying (0), (1) and (2) is a(n), where n is the diagonal, read as a binary number with least significant bit at upper left.
a(n) is also the minimum number of adjacent bit swap operations required to pack all the ones of n to the right. - Philippe Beaudoin, Aug 19 2014
From Rakesh Khanna A, Aug 06 2021: (Start)
a(n) is also the area under the curve formed from the binary representation of n where each 0-bit corresponds to an increase of one unit along the x-axis and each 1-bit corresponds to an increase of one unit along the y-axis.
E.g., n = 20 = 10100_2 and the area under the curve shown below is a(n) = 5.
1 0 1 0 0
\ \ \ \ \ |
\ \ \+----+----+
\ \ | |
\+----+ +
| |
----+----+----+----+
(End)

Examples

			20 = 2^4 + 2^2, thus a(20) = (2-0) + (4-1) = 5.
		

References

  • A. Siegel, Linear Aspects of Boolean Functions, 1999 (unpublished).

Crossrefs

Programs

  • Mathematica
    b[n_] := b[n] = If[n == 0, 0, If[EvenQ[n], b[n/2] + DigitCount[n/2, 2, 1], b[(n - 1)/2] + 1]];
    a[n_] := b[n] - DigitCount[n, 2, 1];
    Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Sep 23 2018 *)
  • PARI
    a(n) = {my(b=binary(n)); nb = 0; for (i=1, #b-1, if (b[i], nb += sum(j=i+1, #b, !b[j]));); nb;} \\ Michel Marcus, Aug 12 2014
    
  • Python
    def A055941(n):
        s = bin(n)[2:]
        return sum(s[i:].count('0') for i,d in enumerate(s,start=1) if d == '1')
    # Chai Wah Wu, Sep 07 2014

Formula

a(n) = Sum (total number of 0-bits to the right of 1-bit) over all 1-bits of n.
a(n) = A161511(n) - A000120(n) = A161920(n+1) - 1 - A029837(n+1).
a(n) = 0 if A241816(n) = n; 1 + a(A241816(n)) otherwise. - Philippe Beaudoin, Aug 19 2014

Extensions

Edited and extended by Antti Karttunen, Oct 12 2009

A246593 a(n)=n for n <= 2; for n >= 3, a(n) = largest number that can be obtained by swapping two bits in the binary expansion of n.

Original entry on oeis.org

0, 1, 2, 3, 4, 6, 6, 7, 8, 12, 12, 14, 12, 14, 14, 15, 16, 24, 24, 26, 24, 28, 28, 30, 24, 28, 28, 30, 28, 30, 30, 31, 32, 48, 48, 50, 48, 52, 52, 54, 48, 56, 56, 58, 56, 60, 60, 62, 48, 56, 56, 58, 56, 60, 60, 62, 56, 60, 60, 62, 60, 62, 62, 63, 64, 96, 96
Offset: 0

Views

Author

N. J. A. Sloane, Sep 03 2014

Keywords

Comments

In both this sequence and A246594 you are not allowed to touch any of the invisible 0's before the leading 1.
Swap first 0 with last 1 in the binary expansion of n or return n if no such swap is possible. - Chai Wah Wu, Sep 08 2014

Examples

			If n = 17 = 10001_2 then a(17) = 11000_2 = 24.
		

Crossrefs

Programs

  • Python
    from itertools import combinations
    def A246593(n):
        if n <= 1:
            return n
        else:
            s, y = bin(n)[2:], n
            for i in combinations(range(len(s)),2):
                s2 = int(s[:i[0]]+s[i[1]]+s[i[0]+1:i[1]]+s[i[0]]+s[i[1]+1:],2)
                if s2 > y:
                    y = s2
            return y
    # Chai Wah Wu, Sep 05 2014
    
  • Python
    # implement algorithm in comment
    def A246593(n):
        s = bin(n)[2:]
        s2 = s.rstrip('0')
        s3 = s2.lstrip('1')
        return(int(s2[:-len(s3)]+'1'+s3[1:-1]+'0'+s[len(s2):],2) if (len(s3) > 0 and n > 1) else n)
    # Chai Wah Wu, Sep 08 2014

Extensions

Corrected definition and more terms from Alois P. Heinz, Sep 04 2014

A246591 Smallest number that can be obtained by swapping 2 bits in the binary expansion of n.

Original entry on oeis.org

0, 1, 1, 3, 1, 3, 3, 7, 1, 3, 3, 7, 5, 7, 7, 15, 1, 3, 3, 7, 5, 7, 7, 15, 9, 11, 11, 15, 13, 15, 15, 31, 1, 3, 3, 7, 5, 7, 7, 15, 9, 11, 11, 15, 13, 15, 15, 31, 17, 19, 19, 23, 21, 23, 23, 31, 25, 27, 27, 31, 29, 31, 31, 63, 1, 3, 3, 7, 5, 7, 7, 15, 9, 11, 11
Offset: 0

Views

Author

N. J. A. Sloane, Sep 03 2014

Keywords

Comments

Swap the first 1 with the last 0 in the binary expansion of n.

Examples

			If n = 12 = 1100_2 then a(12) = 0101_2 = 5.
		

Crossrefs

Programs

  • Python
    from itertools import combinations
    def A246591(n):
        if n <= 1:
            return n
        else:
            s = bin(n)[2:]
            l = len(s)
            y = 2**l-1
            for i in combinations(range(l), 2):
                s2 = int(s[:i[0]]+s[i[1]]+s[i[0]+1:i[1]]+s[i[0]]+s[i[1]+1:], 2)
                if s2 < y:
                    y = s2
            return y
    # Chai Wah Wu, Sep 05 2014
    
  • Python
    def A246591(n):
        s = bin(n)[2:]
        s2 = s.rstrip('1')
        return(int(s2[1:-1]+'1'+s[len(s2):], 2) if (len(s2) > 0 and n > 1) else n)
    # Chai Wah Wu, Sep 08 2014

Extensions

More terms from Alois P. Heinz, Sep 03 2014

A246592 Smallest number that can be obtained by swapping 2 adjacent bits in the binary expansion of n.

Original entry on oeis.org

0, 1, 1, 3, 2, 3, 5, 7, 4, 5, 6, 7, 10, 11, 13, 15, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 26, 27, 29, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 40, 41, 42, 43, 44, 45, 46, 47, 52, 53, 54, 55, 58, 59, 61, 63, 32, 33, 34, 35, 36
Offset: 0

Views

Author

N. J. A. Sloane, Sep 03 2014

Keywords

Comments

Scanning from the left, find first occurrence of '10' in binary expansion and replace with '01' and return decimal representation or return n if no such swap exists. - Chai Wah Wu, Sep 06 2014

Examples

			If n = 9 = 1001_2 then a(9) = 0101_2 = 5.
		

Crossrefs

Programs

  • Mathematica
    A246592[n_] := FromDigits[StringReplace[IntegerString[n, 2], "10" -> "01", 1], 2];
    Array[A246592, 100, 0] (* Paolo Xausa, Mar 07 2025 *)
  • Python
    def A246592(n):
        s = bin(n)[2:]
        for i in range(len(s)-1):
            if s[i:i+2] == '10':
                return int(s[:i]+'01'+s[i+2:], 2)
        else:
            return n # Chai Wah Wu, Sep 06 2014

Extensions

More terms from Alois P. Heinz, Sep 03 2014

A246594 a(n)=n for n <= 2; for n >= 3, a(n) = largest number that can be obtained by swapping two adjacent bits in the binary expansion of n.

Original entry on oeis.org

0, 1, 2, 3, 4, 6, 6, 7, 8, 10, 12, 13, 12, 14, 14, 15, 16, 18, 20, 21, 24, 25, 26, 27, 24, 26, 28, 29, 28, 30, 30, 31, 32, 34, 36, 37, 40, 41, 42, 43, 48, 49, 50, 51, 52, 53, 54, 55, 48, 50, 52, 53, 56, 57, 58, 59, 56, 58, 60, 61, 60, 62, 62, 63, 64, 66, 68
Offset: 0

Views

Author

N. J. A. Sloane, Sep 03 2014

Keywords

Comments

In both this sequence and A246593 you are not allowed to touch any of the invisible 0's before the leading 1.
Scanning from the left, find first occurrence of '01' in binary expansion and replace with '10' and return decimal representation or return n if no such swap exists. - Chai Wah Wu, Sep 06 2014

Examples

			If n = 17 = 10001_2 then a(17) = 10010_2 = 18.
		

Crossrefs

Programs

  • Mathematica
    A246594[n_] := FromDigits[StringReplace[IntegerString[n, 2], "01" -> "10", 1], 2];
    Array[A246594, 100, 0] (* Paolo Xausa, Mar 07 2025 *)
  • Python
    def A246594(n):
        s = bin(n)[2:]
        for i in range(len(s)-1):
            if s[i:i+2] == '01':
                return int(s[:i]+'10'+s[i+2:], 2)
        else:
            return n # Chai Wah Wu, Sep 06 2014

Extensions

Corrected definition and more terms from Alois P. Heinz, Sep 04 2014
Corrected typo in definition - Chai Wah Wu, Sep 06 2014

A243109 a(n) is the largest number smaller than n and having the same Hamming weight as n, or n if no such number exist.

Original entry on oeis.org

0, 1, 1, 3, 2, 3, 5, 7, 4, 6, 9, 7, 10, 11, 13, 15, 8, 12, 17, 14, 18, 19, 21, 15, 20, 22, 25, 23, 26, 27, 29, 31, 16, 24, 33, 28, 34, 35, 37, 30, 36, 38, 41, 39, 42, 43, 45, 31, 40, 44, 49, 46, 50, 51, 53, 47, 52, 54, 57, 55, 58, 59, 61, 63, 32, 48, 65, 56, 66, 67, 69
Offset: 0

Views

Author

Philippe Beaudoin, Aug 20 2014

Keywords

Comments

To calculate a(n), some bits of n are rearranged. The lowest 1-bit which can move down is the 1 of the lowest 10 bit pair in n. This pair becomes 01 in a(n) and any 1's below there move up to immediately below so the decrease is as small as possible. If n has no 10 bit pair (n = 2^k-1) then nothing smaller is possible and a(n) = n. - Kevin Ryde, Mar 01 2021

Examples

			From _Kevin Ryde_, Mar 01 2021: (Start)
                           v    vv
     n = 1475 = binary 10111000011    lowest 10 of n
  a(n) = 1464 = binary 10110111000    becomes 01 and
                            ^^^       other 1's below
(End)
		

Crossrefs

Cf. A057168 (next of same weight), A066884 (array by weight), A241816 (lowest 10->01).

Programs

  • Mathematica
    A243109[n_] := If[# == 0, n, # - 2^(IntegerExponent[#, 2] - IntegerExponent[n+1, 2] - 1)] & [BitAnd[n, n+1]];
    Array[A243109, 100, 0] (* Paolo Xausa, Mar 07 2025 *)
  • PARI
    a(n) = {my(hn = hammingweight(n)); forstep(k=n-1, 1, -1, if (hammingweight(k) == hn, return (k)); ); return (n); } \\ Michel Marcus, Aug 20 2014
    
  • PARI
    a(n) = my(s=n+1,t=bitand(n,s)); if(t==0,n, t - 1<<(valuation(t,2)-valuation(s,2)-1)); \\ Kevin Ryde, Mar 01 2021
    
  • Python
    def A243109(n): return c if (c:=((~n&(b:=n-(a:=~n&n+1)))>>a.bit_length())^b) else n # Chai Wah Wu, Mar 06 2025

Formula

a(n) = t - 2^(A007814(t) - A007814(n+1) - 1) if t!=0, or a(n) = n if t=0, where t = A129760(n+1) is n with any trailing 1's cleared to 0's and A007814 is the 2-adic valuation. - Kevin Ryde, Mar 01 2021
For k,m > 0, a((2^k-1)*2^m) = 2^(m-1)*(2^(k+1)-3). - Chai Wah Wu, Mar 07 2025
If n is even, then a(n) = XOR(n,OR(a,a/2)) where a = AND(-n,n+1). - Chai Wah Wu, Mar 08 2025
Showing 1-7 of 7 results.