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.

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.

This page as a plain text file.
%I A099009 #104 Mar 10 2025 05:24:40
%S A099009 0,495,6174,549945,631764,63317664,97508421,554999445,864197532,
%T A099009 6333176664,9753086421,9975084201,86431976532,555499994445,
%U A099009 633331766664,975330866421,997530864201,999750842001,8643319766532,63333317666664
%N 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.
%C A099009 There are no seven-digit fixed points.
%C A099009 Let d(n) denote n repetitions of the digit d. The sequence includes the following for all n>=0: 5(n)499(n)4(n)5, 63(n)176(n)4, 8643(n)1976(n)532. - _Jens Kruse Andersen_, Oct 04 2004
%C A099009 0's in n giving leading 0's in n'' is allowed.
%C A099009 For every natural number n let n' and n" be the numbers obtained by arranging the digits of n into decreasing and increasing order, and let f(n)=n'-n". It is known that the number 6174 is invariant under this transformation and that applying f a certain number of times to a number n with four digits the numbers 0, 495 or 6174 are always reached. - _Vincenzo Librandi_, Nov 17 2010
%C A099009 Each term of A055162(n) corresponds to A099009(n+1), with its digits being reordered in the ascending manner. - _Alexander R. Povolotsky_, Apr 27 2012
%C A099009 All terms of this sequence are divisible by nine, a(n)/9 = A132155(n). - _Alexander R. Povolotsky_, Apr 29 2012
%C A099009 A055160 differs from this sequence only at the positions of two terms in it: 554999445 and 555499994445. - _Alexander R. Povolotsky_, May 01 2012
%C A099009 The union of the sequences A214555, A214556, A214557, A214558, A214559 and the element 0 gives the sequence A099009. - _Syed Iddi Hasan_, Jul 24 2012
%C A099009 The comment made by Jens Kruse Andersen is missing one more family of terms (which starts with one or more digits "9" and ends with the digit "1"): 97508421, 9753086421, 9975084201, 975330866421, 997530864201, 999750842001, ... This family could be generalized (using the same method as in Andersen's comment) and it is actually covered by _Syed Iddi Hasan_ in A214559. Also A214557 and A214558 (both - by _Syed Iddi Hasan_) are variants of Andersen's 8643(n)1976(n)532. - _Alexander R. Povolotsky_, Mar 14 2015
%C A099009 Fixed points of A151949. - _Reinhard Zumkeller_, Mar 23 2015
%H A099009 Syed Iddi Hasan, <a href="/A099009/b099009.txt">Table of n, a(n) for n = 1..8924</a>
%H A099009 Mauro Fiorentini, <a href="http://www.bitman.name/math/article/654">Kaprekar (costante di)</a> (in Italian)
%H A099009 Manuj Mishra, <a href="/A099009/a099009_1.pdf">Illustration of first 8923 terms, with each digit in a different color</a>
%H A099009 Manuj Mishra, <a href="/A099009/a099009_2.pdf">Illustration as above but only including terms of even length</a>
%H A099009 Manuj Mishra, <a href="/A099009/a099009_3.pdf">Illustration as above but only including terms of odd length</a>
%H A099009 Joseph Myers, <a href="/A099009/a099009.txt">List of cycles under Kaprekar map</a> (all numbers with <= 60 digits; cycles are represented by their smallest value)
%H A099009 Conrad Roche, <a href="http://kaprekar.sourceforge.net">Kaprekar Series Generator</a>.
%H A099009 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/KaprekarRoutine.html">Kaprekar Routine</a>
%H A099009 <a href="/index/K#Kaprekar_map">Index entries for the Kaprekar map</a>
%e A099009 6174 is a fixed point of the mapping and hence a term: 6174 -> 7641 - 1467 = 6174.
%t A099009 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 *)
%o A099009 (Python)
%o A099009 # (version 2.4) from Tim Peters
%o A099009 def extend(base, start, n):
%o A099009     if n == 0:
%o A099009         yield base
%o A099009         return
%o A099009     for i in range(start, 10):
%o A099009         for x in extend(base + str(i), i, n-1):
%o A099009             yield x
%o A099009 def drive(n):
%o A099009     result = []
%o A099009     for lo in extend("", 0, n):
%o A099009         ilo = int(lo)
%o A099009         if ilo == 0 and n > 1:
%o A099009             continue
%o A099009         hi = lo[::-1]
%o A099009         diff = str(int(hi) - ilo)
%o A099009         diff = "0" * (n - len(diff)) + diff
%o A099009         if sorted(diff) == list(lo):
%o A099009             result.append(diff)
%o A099009     return sorted(result)
%o A099009 for n in range(1, 17):
%o A099009     # print("Length", n)
%o A099009     # print('-' * 40)
%o A099009     for r in drive(n):
%o A099009         print(r, end=', ')
%o A099009 (Haskell)
%o A099009 a099009 n = a099009_list !! (n-1)
%o A099009 a099009_list = [x | x <- [0..], a151949 x == x]
%o A099009 -- _Reinhard Zumkeller_, Mar 23 2015
%o A099009 (Magma) a:=func<n|Seqint(Sort(Intseq(n)))-Seqint(Reverse(Sort(Intseq(n)))) eq n>; [k:k in [0..10^7]|a(k)]; // _Marius A. Burtea_, Sep 12 2019
%Y A099009 Cf. A090429, A069746, A099010, A151959, A055162, A132155, A055160, A214557, A214558, A214559
%Y A099009 In other bases: A163205 (base 2), A164997 (base 3), A165016 (base 4), A165036 (base 5), A165055 (base 6), A165075 (base 7), A165094 (base 8), A165114 (base 9).
%Y A099009 Cf. A151949, A004185, A004186.
%K A099009 nonn,base
%O A099009 1,2
%A A099009 _Klaus Brockhaus_, Sep 22 2004
%E A099009 More terms from _Jens Kruse Andersen_ and Tim Peters (tim(AT)python.org), Oct 04 2004
%E A099009 Corrected by _Jens Kruse Andersen_, Oct 25 2004