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.

This page as a plain text file.
%I A153151 #43 Jan 13 2024 10:12:06
%S A153151 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,
%T A153151 25,26,27,28,29,30,63,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
%U A153151 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,127,64,65,66,67,68,69
%N A153151 Rotated binary decrementing: For n<2 a(n) = n, if n=2^k, a(n) = 2*n-1, otherwise a(n) = n-1.
%C A153151 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
%C A153151 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))
%C A153151 1   2 1   3 2 3 1   4  3  5  2  5  3  4  1
%C A153151 where labels  are
%C A153151 1   2 3   4 5 6 7   8  9 10 11 12 13 14 15
%C A153151 to numerators (A002487(n))
%C A153151 1   1 2   1 3 2 3   1  4  3  5  2  5  3  4
%C A153151 where changed labels  are
%C A153151 1   3 2   7 4 5 6  15  8  9 10 11 12 13 14
%C A153151 Thus, b(n) = A002487(n+1), b(a(n)) = A002487(n), n>0. - _Yosu Yurramendi_, Jul 07 2016
%H A153151 A. Karttunen, <a href="/A153151/b153151.txt">Table of n, a(n) for n = 0..2047</a>
%H A153151 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%F A153151 a(n) = A059893(A153141(A059893(n))) = A059894(A153142(A059894(n))).
%p A153151 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
%t A153151 Table[Which[n < 2, n, IntegerQ[Log[2, n]], 2 n - 1, True, n - 1], {n, 0, 70}] (* _Michael De Vlieger_, Apr 27 2015 *)
%o A153151 (MIT/GNU Scheme) (define (A153151 n) (cond ((< n 2) n) ((pow2? n) (- (* 2 n) 1)) (else (- n 1))))
%o A153151 (define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))
%o A153151 (Python)
%o A153151 def ok(n): return n&(n - 1)==0
%o A153151 def a(n): return n if n<2 else 2*n - 1 if ok(n) else n - 1 # _Indranil Ghosh_, Jun 09 2017
%o A153151 (R)
%o A153151 nmax <- 126 # by choice
%o A153151 a <- c(1,3,2)
%o A153151 for(n in 3:nmax) a[n+1] <- n
%o A153151 for(m in 0:floor(log2(nmax))) a[2^m] <- 2^(m+1) - 1
%o A153151 a <- c(0, a)
%o A153151 # _Yosu Yurramendi_, Sep 05 2020
%Y A153151 Inverse: A153152.
%Y A153151 Cf. A059893, A059894, A153141, A153142.
%K A153151 nonn,base
%O A153151 0,3
%A A153151 _Antti Karttunen_, Dec 20 2008