|
|
A057168
|
|
Next larger integer with same binary weight (number of 1 bits) as n.
|
|
27
|
|
|
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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,1
|
|
COMMENTS
|
|
|
REFERENCES
|
Donald Knuth, The Art of Computer Programming, Vol. 4A, section 7.1.3, exercises 20-21.
|
|
LINKS
|
M. Beeler, R. W. Gosper, and R. Schroeppel, HAKMEM, MIT Artificial Intelligence Laboratory, Memo AIM-239, February 1972, Item 175 by Gosper, page 81. Also HTML transcription.
|
|
FORMULA
|
|
|
EXAMPLE
|
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).
|
|
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 *)
|
|
PROG
|
(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
(Python)
def a(n): u = n&-n; v = u+n; return (((v^n)//u)>>2)+v
|
|
CROSSREFS
|
Cf. A000079, A018900, A014311, A014312, A014313, A023688, A023689, A023690, A023691 (Hamming weight = 1, 2, ..., 9).
|
|
KEYWORD
|
easy,nonn,nice
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|