OFFSET
0,3
COMMENTS
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
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Dec 20 2008
STATUS
approved