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.

A271497 If n is a multiple of 3 then a(n) = n/3, otherwise a(n) = n'+n'', where n' (resp. n'') is obtained by sorting the bits of the binary expansion of n into increasing (resp. decreasing) order.

This page as a plain text file.
%I A271497 #16 Apr 16 2016 16:37:43
%S A271497 0,2,3,1,5,9,2,14,9,3,15,21,4,21,21,5,17,27,6,35,27,7,35,45,8,35,35,9,
%T A271497 35,45,10,62,33,11,51,63,12,63,63,13,51,63,14,75,63,15,75,93,16,63,63,
%U A271497 17,63,75,18,93,63,19,75,93,20,93,93,21,65,99,22,119,99,23,119,135,24,119,119,25,119,135
%N A271497 If n is a multiple of 3 then a(n) = n/3, otherwise a(n) = n'+n'', where n' (resp. n'') is obtained by sorting the bits of the binary expansion of n into increasing (resp. decreasing) order.
%H A271497 Chai Wah Wu, <a href="/A271497/b271497.txt">Table of n, a(n) for n = 0..10000</a>
%e A271497 11 = 1011_2, so n' = 0111_2 = 7, n'' = 1110_2 = 14, and therefore a(11) = 7+14 = 21.
%p A271497 A271497:=proc(n) local t1,t2,len; global b;
%p A271497 if n mod (b+1) = 0 then return(n/(b+1)); fi;
%p A271497 t1:=convert(n,base,b); len:=nops(t1);
%p A271497 t2:=sort(t1);
%p A271497 add(t2[i]*(b^(i-1)+b^(len-i)),i=1..len);
%p A271497 end;
%p A271497 b:=2; [seq(A271497(n),n=0..100)];
%o A271497 (Python)
%o A271497 from __future__ import division
%o A271497 def A271497(n):
%o A271497     return int(''.join(sorted(bin(n)[2:])),2) + int(''.join(sorted(bin(n)[2:],reverse=True)),2) if n % 3 else n//3 # _Chai Wah Wu_, Apr 16 2016
%Y A271497 Cf. A052008, A271498, A271500.
%K A271497 nonn,base
%O A271497 0,2
%A A271497 _N. J. A. Sloane_, Apr 16 2016