cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A153151 Rotated binary decrementing: For n<2 a(n) = n, if n=2^k, a(n) = 2*n-1, otherwise a(n) = n-1.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Dec 20 2008

Keywords

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

Crossrefs

Programs

  • 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 *)
  • 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

Formula