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.

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.

This page as a plain text file.
%I A153152 #23 Oct 05 2020 12:49:58
%S A153152 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,
%T A153152 27,28,29,30,31,16,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,
%U A153152 50,51,52,53,54,55,56,57,58,59,60,61,62,63,32,65,66,67,68,69,70,71,72
%N 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.
%C A153152 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
%H A153152 A. Karttunen, <a href="/A153152/b153152.txt">Table of n, a(n) for n = 0..2047</a>
%H A153152 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%p A153152 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
%t A153152 Table[If[IntegerQ@ Log2[n + 1], (n + 1)/2, n + 1], {n, 0, 71}] /. _Rational -> 0 (* _Michael De Vlieger_, Jul 13 2016 *)
%o A153152 (MIT Scheme:) (define (A153152 n) (cond ((< n 2) n) ((pow2? (1+ n)) (/ (1+ n) 2)) (else (1+ n))))
%o A153152 (define (pow2? n) (and (> n 0) (zero? (A004198bi n (- n 1)))))
%o A153152 (Python)
%o A153152 def ok(n): return n&(n - 1)==0
%o A153152 def a(n): return n if n<2 else (n + 1)/2 if ok(n + 1) else n + 1 # _Indranil Ghosh_, Jun 09 2017
%o A153152 (R)
%o A153152 maxlevel <- 5 # by choice
%o A153152 a <- 1
%o A153152 for(m in 1:maxlevel){
%o A153152  a[2^m        ] <- 2^m + 1
%o A153152  a[2^(m+1) - 1] <- 2^m
%o A153152  for (k in 0:(2^m-2)){
%o A153152    a[2^(m+1) + 2*k + 1] <- 2*a[2^m + k]
%o A153152    a[2^(m+1) + 2*k + 2] <- 2*a[2^m + k] + 1}
%o A153152 }
%o A153152 a <- c(0, a)
%o A153152 # _Yosu Yurramendi_, Sep 05 2020
%Y A153152 Inverse: A153151.
%Y A153152 a(n) = A059893(A153142(A059893(n))) = A059894(A153141(A059894(n))).
%K A153152 nonn,base
%O A153152 0,3
%A A153152 _Antti Karttunen_, Dec 20 2008