login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A153151
Rotated binary decrementing: For n<2 a(n) = n, if n=2^k, a(n) = 2*n-1, otherwise a(n) = n-1.
8
0, 1, 3, 2, 7, 4, 5, 6, 15, 8, 9, 10, 11, 12, 13, 14, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 63, 32, 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, 127, 64, 65, 66, 67, 68, 69
OFFSET
0,3
COMMENTS
Without the initial 0, a(n) is the lexicographically minimal sequence of distinct positive integers such that all values of a(n) mod n are distinct and nonnegative. - Ivan Neretin, Apr 27 2015
A002487(n)/A002487(n+1), n > 0, runs through all the reduced nonnegative rationals exactly once. A002487 is the Stern's sequence. Permutation from denominators (A002487(n+1))
1 2 1 3 2 3 1 4 3 5 2 5 3 4 1
where labels are
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
to numerators (A002487(n))
1 1 2 1 3 2 3 1 4 3 5 2 5 3 4
where changed labels are
1 3 2 7 4 5 6 15 8 9 10 11 12 13 14
Thus, b(n) = A002487(n+1), b(a(n)) = A002487(n), n>0. - Yosu Yurramendi, Jul 07 2016
FORMULA
MAPLE
a := n -> if n < 2 then n elif convert(convert(n, base, 2), `+`) = 1 then 2*n-1 else n-1 fi: seq(a(n), n=0..70); # Peter Luschny, Jul 16 2016
MATHEMATICA
Table[Which[n < 2, n, IntegerQ[Log[2, n]], 2 n - 1, True, n - 1], {n, 0, 70}] (* Michael De Vlieger, Apr 27 2015 *)
PROG
(MIT/GNU Scheme) (define (A153151 n) (cond ((< n 2) n) ((pow2? n) (- (* 2 n) 1)) (else (- n 1))))
(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 2*n - 1 if ok(n) else n - 1 # Indranil Ghosh, Jun 09 2017
(R)
nmax <- 126 # by choice
a <- c(1, 3, 2)
for(n in 3:nmax) a[n+1] <- n
for(m in 0:floor(log2(nmax))) a[2^m] <- 2^(m+1) - 1
a <- c(0, a)
# Yosu Yurramendi, Sep 05 2020
CROSSREFS
Inverse: A153152.
Sequence in context: A135542 A130109 A334998 * A175057 A153154 A154438
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Dec 20 2008
STATUS
approved