login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A153152 Rotated binary incrementing: For n<2 a(n)=n, if n=(2^k)-1, a(n)=(n+1)/2, otherwise a(n)=n+1. 5
0, 1, 3, 2, 5, 6, 7, 4, 9, 10, 11, 12, 13, 14, 15, 8, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 32, 65, 66, 67, 68, 69, 70, 71, 72 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,3
COMMENTS
A002487(n)/A002487(n+1), n > 0, runs through all the reduced nonnegative rationals exactly once. A002487 is the Stern's sequence. A002487(a(n)) = A002487(n+1) n>0 . - Yosu Yurramendi, Jul 07 2016
LINKS
MAPLE
a := n -> if n < 2 then n elif convert(convert(n+1, base, 2), `+`) = 1 then (n+1)/2 else n+1 fi: seq(a(n), n=0..71); # Peter Luschny, Jul 16 2016
MATHEMATICA
Table[If[IntegerQ@ Log2[n + 1], (n + 1)/2, n + 1], {n, 0, 71}] /. _Rational -> 0 (* Michael De Vlieger, Jul 13 2016 *)
PROG
(MIT Scheme:) (define (A153152 n) (cond ((< n 2) n) ((pow2? (1+ n)) (/ (1+ n) 2)) (else (1+ n))))
(define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))
(Python)
def ok(n): return n&(n - 1)==0
def a(n): return n if n<2 else (n + 1)/2 if ok(n + 1) else n + 1 # Indranil Ghosh, Jun 09 2017
(R)
maxlevel <- 5 # by choice
a <- 1
for(m in 1:maxlevel){
a[2^m ] <- 2^m + 1
a[2^(m+1) - 1] <- 2^m
for (k in 0:(2^m-2)){
a[2^(m+1) + 2*k + 1] <- 2*a[2^m + k]
a[2^(m+1) + 2*k + 2] <- 2*a[2^m + k] + 1}
}
a <- c(0, a)
# Yosu Yurramendi, Sep 05 2020
CROSSREFS
Inverse: A153151.
Sequence in context: A276618 A293722 A364254 * A153153 A175058 A250090
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Dec 20 2008
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 23 14:32 EDT 2024. Contains 371914 sequences. (Running on oeis4.)