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

A057168 Next larger integer with same binary weight (number of 1 bits) as n.

Original entry on oeis.org

2, 4, 5, 8, 6, 9, 11, 16, 10, 12, 13, 17, 14, 19, 23, 32, 18, 20, 21, 24, 22, 25, 27, 33, 26, 28, 29, 35, 30, 39, 47, 64, 34, 36, 37, 40, 38, 41, 43, 48, 42, 44, 45, 49, 46, 51, 55, 65, 50, 52, 53, 56, 54, 57, 59, 67, 58, 60, 61, 71, 62, 79, 95, 128, 66, 68, 69, 72, 70, 73, 75
Offset: 1

Views

Author

Marc LeBrun, Sep 14 2000

Keywords

Comments

Binary weight is given by A000120.

Examples

			a(6)=9 since 6 has two one-bits (i.e., 6=2+4) and 9 is the next higher integer of binary weight two (7 is weight three and 8 is weight one).
		

References

  • Donald Knuth, The Art of Computer Programming, Vol. 4A, section 7.1.3, exercises 20-21.

Crossrefs

Programs

  • Haskell
    a057168 n = a057168_list !! (n-1)
    a057168_list = f 2 $ tail a000120_list where
       f x (z:zs) = (x + length (takeWhile (/= z) zs)) : f (x + 1) zs
    -- Reinhard Zumkeller, Aug 26 2012
    
  • Mathematica
    a[n_] := (bw = DigitCount[n, 2, 1]; k = n+1; While[ DigitCount[k, 2, 1] != bw, k++]; k); Table[a[n], {n, 1, 71}](* Jean-François Alcover, Nov 28 2011 *)
  • PARI
    a(n)=my(u=bitand(n,-n),v=u+n);(bitxor(v,n)/u)>>2+v \\ Charles R Greathouse IV, Oct 28 2009
    
  • PARI
    A057168(n)=n+bitxor(n,n+n=bitand(n,-n))\n\4+n \\ M. F. Hasler, Aug 27 2014
    
  • Python
    def a(n): u = n&-n; v = u+n; return (((v^n)//u)>>2)+v
    print([a(n) for n in range(1, 72)]) # Michael S. Branicky, Jul 10 2022 after Charles R Greathouse IV
    
  • Python
    def A057168(n): return ((n&~(b:=n+(a:=n&-n)))>>a.bit_length())^b # Chai Wah Wu, Mar 06 2025

Formula

From Reinhard Zumkeller, Aug 18 2008: (Start)
a(A000079(n)) = A000079(n+1);
a(A000051(n)) = A052548(n);
a(A052548(n)) = A140504(n);
a(A000225(n)) = A055010(n);
a(A007283(n)) = A000051(n+2). (End)
a(n) = MIN{m: A000120(m)=A000120(n) and m>n}. - Reinhard Zumkeller, Aug 15 2009
For k,m>0, a((2^k-1)*2^m) = 2^(k+m)+2^(k-1)-1. - Chai Wah Wu, Mar 07 2025
If n is odd, then a(n) = XOR(n,OR(a,a/2)) where a = AND(-n,n+1). - Chai Wah Wu, Mar 08 2025

A171898 Forward van Eck transform of A181391.

Original entry on oeis.org

1, 2, 6, 2, 2, 5, 1, 6, 42, 5, 2, 4, 5, 9, 14, 3, 9, 3, 15, 2, 4, 6, 17, 3, 6, 32, 56, 5, 3, 131, 5, 11, 5, 3, 20, 6, 2, 8, 15, 31, 170, 3, 31, 18, 3, 3, 33, 5, 1, 11, 46, 56, 4, 37, 152, 307, 3, 7, 92, 4, 7, 62, 52, 3, 42, 3, 6, 2, 19, 6, 8, 3, 9, 3, 650, 2, 23, 8, 223, 7, 206, 3, 21, 25, 5, 8
Offset: 1

Views

Author

N. J. A. Sloane, Oct 22 2010

Keywords

Comments

Given a sequence a, the forward van Eck transform b is defined as follows: If a(n) also appears again in a later position, let a(m) be the next occurrence, and set b(n)=m-n; otherwise b(n)=0.
This is a permutation of the positive terms in A181391, where each term m > 0 from that sequence is shifted backwards m+1 positions. - Jan Ritsema van Eck, Aug 16 2019
The backwards van Eck transform searches backwards for a repeated value: if a(n) also has appeared in earlier positions, a(m)=a(n) with mR. J. Mathar, Jun 24 2021

Crossrefs

Cf. A181391 (van Eck's sequence), A171899, A171942.

Programs

  • Maple
    ECKf:=proc(a) local b,i,m,n;
    if whattype(a) <> list then RETURN([]); fi:
    b:=[];
    for n from 1 to nops(a)-1 do
    # does a(n) appear again?
    m:=0;
    for i from n+1 to nops(a) do
    if (a[i]=a[n]) then m:=i-n; break; fi
    od:
    b:=[op(b),m];
    od:
    b:=[op(b),0];
    RETURN(b);
    end:
  • Mathematica
    terms = 100;
    m = 14 terms; (* Increase m until no zero appears in the output *)
    ClearAll[b, last]; b[] = 0; last[] = -1; last[0] = 2; nxt = 1;
    Do[hist = last[nxt]; b[n] = nxt; last[nxt] = n; nxt = 0; If[hist > 0, nxt = n - hist], {n, 3, m}];
    A181391 = Array[b, m];
    ECKf[a_List] := Module[{b = {}, i, m, n}, For[n = 1, n <= Length[a]-1, n++, m = 0; For[i = n+1, i <= Length[a], i++, If[a[[i]] == a[[n]], m = i-n; Break[]]]; b = Append[b, m]]; b = Append[b, 0]; Return[b]];
    ECKf[A181391][[;; terms]] (* Jean-François Alcover, Oct 30 2020, after Maple *)

Formula

From Jan Ritsema van Eck, Aug 16 2019: (Start)
A181391(i+a(i)+1) = a(i) for any i, a(i)>0.
Conversely, a(j-A181391(j)-1) = A181391(j) for any j, A181391(j)>0. (End)
Showing 1-2 of 2 results.