A164884 a(n) = image of n under the base-2 Kaprekar map n -> (n with digits sorted into descending order) - (n with digits sorted into ascending order).
0, 0, 1, 0, 3, 3, 3, 0, 7, 9, 9, 7, 9, 7, 7, 0, 15, 21, 21, 21, 21, 21, 21, 15, 21, 21, 21, 15, 21, 15, 15, 0, 31, 45, 45, 49, 45, 49, 49, 45, 45, 49, 49, 45, 49, 45, 45, 31, 45, 49, 49, 45, 49, 45, 45, 31, 49, 45, 45, 31, 45, 31, 31, 0, 63, 93, 93, 105, 93, 105, 105, 105, 93, 105, 105
Offset: 0
Examples
For n = 17, 17_10 = 10001_2. So, a(17) = 11000_2 - 11_2 = 24 - 3 = 21. - _Indranil Ghosh_, Feb 01 2017
Links
- Indranil Ghosh, Table of n, a(n) for n = 0..16384 (terms 0..1024 from Joseph Myers)
- Index entries for the Kaprekar map
Crossrefs
Programs
-
Mathematica
a[n_] := With[{dd = IntegerDigits[n, 2]}, FromDigits[ReverseSort[dd], 2] - FromDigits[Sort[dd], 2]]; a /@ Range[0, 100] (* Jean-François Alcover, Jan 08 2020 *)
-
Python
def A164884(n): return int("".join(sorted(bin(n)[2:],reverse=True)),2)-int("".join(sorted(bin(n)[2:])),2) # Indranil Ghosh, Feb 01 2017
Extensions
Cross-references edited by Joseph Myers, Sep 04 2009