A099009 Fixed points of the Kaprekar mapping f(n) = n' - n'', where in n' the digits of n are arranged in descending, in n'' in ascending order.
0, 495, 6174, 549945, 631764, 63317664, 97508421, 554999445, 864197532, 6333176664, 9753086421, 9975084201, 86431976532, 555499994445, 633331766664, 975330866421, 997530864201, 999750842001, 8643319766532, 63333317666664
Offset: 1
Examples
6174 is a fixed point of the mapping and hence a term: 6174 -> 7641 - 1467 = 6174.
Links
- Syed Iddi Hasan, Table of n, a(n) for n = 1..8924
- Mauro Fiorentini, Kaprekar (costante di) (in Italian)
- Manuj Mishra, Illustration of first 8923 terms, with each digit in a different color
- Manuj Mishra, Illustration as above but only including terms of even length
- Manuj Mishra, Illustration as above but only including terms of odd length
- Joseph Myers, List of cycles under Kaprekar map (all numbers with <= 60 digits; cycles are represented by their smallest value)
- Conrad Roche, Kaprekar Series Generator.
- Eric Weisstein's World of Mathematics, Kaprekar Routine
- Index entries for the Kaprekar map
Crossrefs
Programs
-
Haskell
a099009 n = a099009_list !! (n-1) a099009_list = [x | x <- [0..], a151949 x == x] -- Reinhard Zumkeller, Mar 23 2015
-
Magma
a:=func
; [k:k in [0..10^7]|a(k)]; // Marius A. Burtea, Sep 12 2019 -
Mathematica
f[n_] := Block[{d = IntegerDigits@ n, a, b}, a = FromDigits@ Sort@ d; b = FromDigits@ Reverse@ Sort@ d; n == b - a]; Select[Range@ 1000000, f] (* Michael De Vlieger, Mar 20 2015 *)
-
Python
# (version 2.4) from Tim Peters def extend(base, start, n): if n == 0: yield base return for i in range(start, 10): for x in extend(base + str(i), i, n-1): yield x def drive(n): result = [] for lo in extend("", 0, n): ilo = int(lo) if ilo == 0 and n > 1: continue hi = lo[::-1] diff = str(int(hi) - ilo) diff = "0" * (n - len(diff)) + diff if sorted(diff) == list(lo): result.append(diff) return sorted(result) for n in range(1, 17): # print("Length", n) # print('-' * 40) for r in drive(n): print(r, end=', ')
Extensions
More terms from Jens Kruse Andersen and Tim Peters (tim(AT)python.org), Oct 04 2004
Corrected by Jens Kruse Andersen, Oct 25 2004
Comments