A165012 a(n) = image of n under the base-4 Kaprekar map n -> (n with digits sorted into descending order) - (n with digits sorted into ascending order).
0, 0, 0, 0, 3, 0, 3, 6, 6, 3, 0, 3, 9, 6, 3, 0, 15, 15, 30, 45, 15, 0, 15, 30, 30, 15, 15, 30, 45, 30, 30, 30, 30, 30, 30, 45, 30, 15, 15, 30, 30, 15, 0, 15, 45, 30, 15, 15, 45, 45, 45, 45, 45, 30, 30, 30, 45, 30, 15, 15, 45, 30, 15, 0, 63, 75, 138, 201, 75, 63, 126, 189, 138, 126
Offset: 0
Examples
For n = 11, 11_10 = 23_4. So, a(11) = 32_4 - 23_4 = 14 - 11 = 3. - _Indranil Ghosh_, Feb 02 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
b4km[n_]:=Module[{idn4=Sort[IntegerDigits[n,4]]},FromDigits[ Reverse[ idn4],4]-FromDigits[idn4,4]]; Array[b4km,80,0]
-
PARI
cons(m) = {local(b, r); r=0; b=1; for(i=1, matsize(m)[2], r=r+b*m[i]; b=b*4); r} A165012(n) = {local(m, r); r=[]; m=n; while(m>0, r=concat(m%4, r); m=floor(m/4)); cons(vecsort(r,,0))-cons(vecsort(r,,4))} \\ Michael B. Porter, Nov 05 2009