A059893
Reverse the order of all but the most significant bit in binary expansion of n: if n = 1ab..yz then a(n) = 1zy..ba.
Original entry on oeis.org
1, 2, 3, 4, 6, 5, 7, 8, 12, 10, 14, 9, 13, 11, 15, 16, 24, 20, 28, 18, 26, 22, 30, 17, 25, 21, 29, 19, 27, 23, 31, 32, 48, 40, 56, 36, 52, 44, 60, 34, 50, 42, 58, 38, 54, 46, 62, 33, 49, 41, 57, 37, 53, 45, 61, 35, 51, 43, 59, 39, 55, 47, 63, 64, 96, 80, 112, 72, 104, 88, 120
Offset: 1
a(11) = a(1011) = 1110 = 14.
With empty word e prefixed, A081242 becomes (e,1,2,11,21,12,22,111,211,121,221,112,...); (reversal of term #9) = (term #12); i.e., a(9)=12 and a(12)=9. - _Clark Kimberling_, Mar 12 2003
From _Philippe Deléham_, Jun 02 2015: (Start)
This sequence regarded as a triangle with rows of lengths 1, 2, 4, 8, 16, ...:
1;
2, 3;
4, 6, 5, 7;
8, 12, 10, 14, 9, 13, 11, 15;
16, 24, 20, 28, 18, 26, 22, 30, 17, 25, 21, 29, 19, 27, 23, 31;
32, 48, 40, 56, 36, 52, 44, ...
Row sums = A010036. (End)
- Alois P. Heinz, Table of n, a(n) for n = 1..8191 (first 1023 terms from T. D. Noe)
- Bruce Bates, Martin Bunder, and Keith Tognetti, Locating terms in the Stern-Brocot tree, European Journal of Combinatorics 31.3 (2010): 1020-1033.
- Joe Buhler and R. L. Graham, Juggling Drops and Descents, Amer. Math. Monthly, 101, (no. 6) 1994, 507-519.
- Dana G. Korssjoen, Biyao Li, Stefan Steinerberger, Raghavendra Tripathi, and Ruimin Zhang, Finding structure in sequences of real numbers via graph theory: a problem list, arXiv:2012.04625, 2020-2021.
- Wikipedia, Calkin-Wilf Tree.
- Wikipedia, Stern-Brocot tree.
- Index entries for sequences related to Stern's sequences
- Index entries for sequences that are permutations of the natural numbers
-
a059893 = foldl (\v b -> v * 2 + b) 1 . init . a030308_row
-- Reinhard Zumkeller, May 01 2013
(Scheme, with memoization-macro definec)
(definec (A059893 n) (if (<= n 1) n (let* ((k (- (A000523 n) 1)) (r (A059893 (- n (A000079 k))))) (if (= 2 (floor->exact (/ n (A000079 k)))) (* 2 r) (+ 1 r)))))
;; Antti Karttunen, May 16 2015
-
# Implements Bottomley's formula
A059893 := proc(n) option remember; local k; if(1 = n) then RETURN(1); fi; k := floor_log_2(n)-1; if(2 = floor(n/(2^k))) then RETURN(2*A059893(n-(2^k))); else RETURN(1+A059893(n-(2^k))); fi; end;
floor_log_2 := proc(n) local nn,i; nn := n; for i from -1 to n do if(0 = nn) then RETURN(i); fi; nn := floor(nn/2); od; end;
# second Maple program:
a:= proc(n) local i, m, r; m, r:= n, 0;
for i from 0 while m>1 do r:= 2*r +irem(m,2,'m') od;
r +2^i
end:
seq(a(n), n=1..100); # Alois P. Heinz, Feb 28 2015
-
A059893 = Reap[ For[n=1, n <= 100, n++, a=1; b=n; While[b > 1, a = 2*a + 2*FractionalPart[b/2]; b=Floor[b/2]]; Sow[a]]][[2, 1]] (* Jean-François Alcover, Jul 16 2012, after Harry J. Smith *)
ro[n_]:=Module[{idn=IntegerDigits[n,2]},FromDigits[Join[{First[idn]}, Reverse[ Rest[idn]]],2]]; Array[ro,80] (* Harvey P. Dale, Oct 24 2012 *)
-
a(n) = my(b=binary(n)); fromdigits(concat(b[1], Vecrev(vector(#b-1, k, b[k+1]))), 2); \\ Michel Marcus, Sep 29 2021
-
def a(n): return int('1' + bin(n)[3:][::-1], 2)
print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Mar 21 2017
-
maxrow <- 6 # by choice
a <- 1
for(m in 0:maxrow) for(k in 0:(2^m-1)) {
a[2^(m+1)+ k] <- 2*a[2^m+k]
a[2^(m+1)+2^m+k] <- 2*a[2^m+k] + 1
}
a
# Yosu Yurramendi, Mar 20 2017
-
maxblock <- 7 # by choice
a <- 1
for(n in 2:2^maxblock){
ones <- which(as.integer(intToBits(n)) == 1)
nbit <- as.integer(intToBits(n))[1:tail(ones, n = 1)]
anbit <- nbit
anbit[1:(length(anbit) - 1)] <- anbit[rev(1:(length(anbit)-1))]
a <- c(a, sum(anbit*2^(0:(length(anbit) - 1))))
}
a
# Yosu Yurramendi, Apr 25 2021
A343150
Reverse the order of all but the most significant bits in the minimal Fibonacci expansion of n.
Original entry on oeis.org
1, 2, 3, 4, 5, 7, 6, 8, 11, 10, 9, 12, 13, 18, 16, 15, 20, 14, 19, 17, 21, 29, 26, 24, 32, 23, 31, 28, 22, 30, 27, 25, 33, 34, 47, 42, 39, 52, 37, 50, 45, 36, 49, 44, 41, 54, 35, 48, 43, 40, 53, 38, 51, 46, 55, 76, 68, 63, 84, 60, 81, 73, 58, 79, 71, 66, 87
Offset: 1
For an example of calculation by reversing Fibonacci binary digits, see reference in link, p. 144:
On the basis (1,1,2,3,5,8,13) n=13 is written as 0000001. Reversing all but the most significant digit gives 0000001, which evaluates to 13, so a(13)=13.
On the basis (1,1,2,3,5,8,13) n=14 is written as 0100001. Reversing all but the most significant digit gives 0000101, which evaluates to 18, so a(14)=18.
Note: The permutation can also be accomplished using the basis (1,2,3,5,8,13), by holding fixed the TWO most significant digits and reversing the remaining digits.
-
(*Produce indices of minimal Fibonacci representation (recursively)*)
MinFibInd[n_] := Module[{t = Floor[Log[GoldenRatio, Sqrt[5]*n + 1]] - 1}, Piecewise[{{{2}, n == 1}, {Append[MinFibInd[n - Fibonacci[t + 1]], t + 1], n > 1 && n - Fibonacci[t + 1] >= Fibonacci[t - 1]}, {Append[Most[MinFibInd[n - Fibonacci[t - 1]]], t + 1], n > 1 && n - Fibonacci[t + 1] < Fibonacci[t - 1]}},]];
(*Define a(n)*)
a[n_] := Module[{MFI = MinFibInd[n]}, Apply[Plus, Fibonacci[Append[Last[MFI] - Most[MFI], Last[MFI]]]]];
(*Generate DATA*)
Array[a, 67]
A353654
Numbers whose binary expansion has the same number of trailing 0 bits as other 0 bits.
Original entry on oeis.org
1, 3, 7, 10, 15, 22, 26, 31, 36, 46, 54, 58, 63, 76, 84, 94, 100, 110, 118, 122, 127, 136, 156, 172, 180, 190, 204, 212, 222, 228, 238, 246, 250, 255, 280, 296, 316, 328, 348, 364, 372, 382, 392, 412, 428, 436, 446, 460, 468, 478, 484, 494, 502, 506, 511, 528, 568
Offset: 1
Cf.
A000045,
A000120,
A000523,
A007814,
A010056,
A025480,
A030109,
A054429,
A060142,
A072649,
A084471,
A086784,
A091892,
A132665,
A133512,
A200650,
A213911,
A232559,
A280514,
A343152,
A348366.
-
N:= 10: # for terms <= 2^N
S:= {1};
for d from 1 to N do
for k from 0 to d/2-1 do
B:= combinat:-choose([$k+1..d-2],k);
S:= S union convert(map(proc(t) local s; 2^d - 2^k - add(2^(s),s=t) end proc,B),set);
od od:
sort(convert(S,list)); # Robert Israel, Sep 21 2023
-
Join[{1}, Select[Range[2, 600], IntegerExponent[#, 2] == Floor[Log2[# - 1]] - DigitCount[# - 1, 2, 1] &]] (* Amiram Eldar, Jul 16 2022 *)
-
isok(k) = if (k==1, 1, (logint(k-1, 2)-hammingweight(k-1) == valuation(k, 2))); \\ Michel Marcus, Jul 16 2022
-
from itertools import islice, count
def A353654_gen(startvalue=1): # generator of terms >= startvalue
return filter(lambda n:(m:=(~n & n-1).bit_length()) == bin(n>>m)[2:].count('0'),count(max(startvalue,1)))
A353654_list = list(islice(A353654_gen(),30)) # Chai Wah Wu, Oct 14 2022
Original entry on oeis.org
0, 1, 3, 2, 7, 5, 6, 15, 4, 11, 13, 14, 31, 9, 10, 23, 12, 27, 29, 30, 63, 8, 19, 21, 22, 47, 25, 26, 55, 28, 59, 61, 62, 127, 17, 18, 39, 20, 43, 45, 46, 95, 24, 51, 53, 54, 111, 57, 58, 119, 60, 123, 125, 126, 255, 16, 35, 37, 38, 79, 41, 42, 87, 44, 91, 93
Offset: 0
A345253
Maximal Fibonacci tree: Arrangement of the positive integers as labels of a complete binary tree.
Original entry on oeis.org
1, 2, 3, 4, 5, 6, 8, 7, 9, 10, 13, 11, 14, 16, 21, 12, 15, 17, 22, 18, 23, 26, 34, 19, 24, 27, 35, 29, 37, 42, 55, 20, 25, 28, 36, 30, 38, 43, 56, 31, 39, 44, 57, 47, 60, 68, 89, 32, 40, 45, 58, 48, 61, 69, 90, 50, 63, 71, 92, 76, 97, 110, 144, 33, 41, 46, 59, 49
Offset: 1
As a complete binary tree:
1
/ \
2 3
/ \ / \
4 5 6 8
/ \ / \ / \ / \
7 9 10 13 11 14 16 21
/ \ / \ / \ / \ / \ / \ / \ / \
...
By maximal Fibonacci expansion:
F(1)
/ \
F(1) + F(2) F(1) + F(3)
/ \ / \
F(1) + F(2) + F(3) F(1) + F(2) + F(4) F(1) + F(3) + F(4) F(1) + F(3) + F(5)
...
"Fibonacci gaps," or differences between successive indices in maximal Fibonacci expansion above, are A007931(n-1) for n > 1 (see link):
*
/ \
1 2
/ \ / \
11 12 21 22
/ \ / \ / \ / \
111 112 121 122 211 212 221 222
/ \ / \ / \ / \ / \ / \ / \ / \
...
In examples of the three methods below:
Branch left-right-right down the tree to arrive at nodal position n = 2*(2*(2*1) + 1) + 1 = 11;
Branch right-left-left down the tree to arrive at nodal position n = 2*(2*(2*1 + 1)) = 12.
Tree by inner composition of (one plus) the lower and upper Wythoff sequences, A000201 and A001950 (Method 1):
a(11) = A000201(A001950(A001950(1) + 1) + 1) + 1 = 13.
a(12) = A001950(A000201(A000201(1) + 1) + 1) + 1 = 11.
Tree by (outer) composition of branching functions L(n) = n + F(Finv(n)) and R(n) = n + F(Finv(n) + 1), where F(n) = A000045(n) and Finv(n) = A130233(n) (Method 2):
a(11) = R(R(L(1))) = 13.
a(12) = L(R(R(1))) = 11.
Tree by outer composition of A060143 and A060144 (Wythoff inverse sequences) (Method 3):
a(11) = 13, position of first nonzero in A060144(A060144(A060143(m))) = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., for m = 1, 2, 3, ....
a(12) = 11, position of first nonzero in A060143(A060143(A060144(m))) = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ..., for m = 1, 2, 3, ....
Cf.
A000045,
A000201,
A001950,
A007931,
A020988,
A020989,
A026351,
A026352,
A029837,
A048680,
A049651,
A059893,
A061547,
A070939,
A081242,
A083047,
A095903,
A099919,
A112310,
A113473,
A130233,
A200648,
A232560,
A243571,
A255773,
A255774,
A329395,
A343152,
A345252,
A345254.
-
(* For binary tree implementations, see supporting file under LINKS *)
a[n_] := (x = 0; y = 0; BDn = Reverse[IntegerDigits[n, 2]]; imax = Length[BDn] - 1; For[i = 0, i <= imax, i++, {x, y} = {y + 1, x + y}; If[BDn[[i + 1]] == 1, {x, y} = {y, x + y}]]; y);
(* Adapted from PARI code of Kevin Ryde *)
-
a(n) = my(x=0,y=0); for(i=0,logint(n,2), [x,y]=[y+1,x+y]; if(bittest(n,i), [x,y]=[y,x+y])); y; \\ Kevin Ryde, Jun 19 2021
A351702
In the balanced ternary representation of n, reverse the order of digits other than the most significant.
Original entry on oeis.org
0, 1, 2, 3, 4, 5, 8, 11, 6, 9, 12, 7, 10, 13, 14, 23, 32, 17, 26, 35, 20, 29, 38, 15, 24, 33, 18, 27, 36, 21, 30, 39, 16, 25, 34, 19, 28, 37, 22, 31, 40, 41, 68, 95, 50, 77, 104, 59, 86, 113, 44, 71, 98, 53, 80, 107, 62, 89, 116, 47, 74, 101, 56, 83, 110, 65, 92
Offset: 0
n = 224 = balanced ternary 1, 0, -1, 1, 0, -1
reverse ^^^^^^^^^^^^^^^^
a(n) = 168 = balanced ternary 1, -1, 0, 1, -1, 0
-
a(n) = if(n==0,0, my(k=if(n,logint(n<<1,3)), s=(3^k+1)>>1); s + fromdigits(Vec(Vecrev(digits(n-s,3)),k),3));
Showing 1-6 of 6 results.
Comments