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.

Showing 1-7 of 7 results.

A151949 a(n) = image of n under the Kaprekar map n -> (n with digits sorted into descending order) - (n with digits sorted into ascending order).

Original entry on oeis.org

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 9, 18, 27, 36, 45, 54, 63, 72, 18, 9, 0, 9, 18, 27, 36, 45, 54, 63, 27, 18, 9, 0, 9, 18, 27, 36, 45, 54, 36, 27, 18, 9, 0, 9, 18, 27, 36, 45, 45, 36, 27, 18, 9, 0, 9, 18, 27, 36, 54, 45, 36, 27, 18, 9, 0, 9, 18, 27, 63, 54, 45, 36, 27, 18, 9, 0, 9, 18, 72, 63, 54, 45, 36, 27, 18, 9, 0, 9, 81, 72, 63, 54, 45, 36, 27, 18, 9, 0, 99, 99, 198, 297, 396, 495, 594, 693, 792, 891, 99, 0, 99, 198, 297, 396, 495, 594, 693, 792
Offset: 0

Views

Author

N. J. A. Sloane, Aug 18 2009

Keywords

Comments

Entries are multiples of 9 - see A151950.
a(n) = A004186(n) - A004185(n); a(A010785(n)) = 0. - Reinhard Zumkeller, corrected: Mar 23 2015, Jul 09 2013

Examples

			For n = 15, a(15) = 51 - 15 = 36. - _Indranil Ghosh_, Feb 01 2017
		

Crossrefs

In other bases: A164884 (base 2), A164993 (base 3), A165012 (base 4), A165032 (base 5), A165051 (base 6), A165071 (base 7), A165090 (base 8), A165110 (base 9). - Joseph Myers, Sep 05 2009
Cf. also A004185, A004186, A099009 (fixed points).

Programs

  • Haskell
    a151949 n = a004186 n - a004185 n
    -- Reinhard Zumkeller, corrected: Mar 23 2015, Jul 09 2013
    
  • Mathematica
    f[n_] := Module[{idn = IntegerDigits@n, idns}, idns = Sort@ idn; FromDigits@ Reverse@ idns - FromDigits@ idns]; Table[ f@n, {n, 0, 200}] (* Harvey P. Dale, Aug 18 2009 *)
    Flatten[Table[Differences[FromDigits /@ {y = Sort[x = IntegerDigits[n]], Reverse[y]}], {n, 0, 74}]] (* Jayanta Basu, Jul 11 2013 *)
  • PARI
    a(n) = {my(d=digits(n)); fromdigits(vecsort(d,,4)) - fromdigits(vecsort(d));} \\ Michel Marcus, Dec 08 2019
  • Python
    def A151949(n):
        return int("".join(sorted(str(n),reverse=True)))-int("".join(sorted(str(n)))) # Indranil Ghosh, Feb 01 2017
    

Extensions

More terms from Robert G. Wilson v, Aug 19 2009
More than the usual number of terms are shown in order to distinguish this from similar sequences. - N. J. A. Sloane, Sep 22 2021

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.

Original entry on oeis.org

0, 495, 6174, 549945, 631764, 63317664, 97508421, 554999445, 864197532, 6333176664, 9753086421, 9975084201, 86431976532, 555499994445, 633331766664, 975330866421, 997530864201, 999750842001, 8643319766532, 63333317666664
Offset: 1

Views

Author

Klaus Brockhaus, Sep 22 2004

Keywords

Comments

There are no seven-digit fixed points.
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
0's in n giving leading 0's in n'' is allowed.
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
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
All terms of this sequence are divisible by nine, a(n)/9 = A132155(n). - Alexander R. Povolotsky, Apr 29 2012
A055160 differs from this sequence only at the positions of two terms in it: 554999445 and 555499994445. - Alexander R. Povolotsky, May 01 2012
The union of the sequences A214555, A214556, A214557, A214558, A214559 and the element 0 gives the sequence A099009. - Syed Iddi Hasan, Jul 24 2012
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
Fixed points of A151949. - Reinhard Zumkeller, Mar 23 2015

Examples

			6174 is a fixed point of the mapping and hence a term: 6174 -> 7641 - 1467 = 6174.
		

Crossrefs

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).

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

A099010 Consider the Kaprekar map n->K(n) defined in A151949. Sequence gives numbers belonging to cycles of length greater than 1.

Original entry on oeis.org

53955, 59994, 61974, 62964, 63954, 71973, 74943, 75933, 82962, 83952, 420876, 642654, 750843, 840852, 851742, 860832, 862632, 7509843, 7519743, 7619733, 8429652, 8439552, 8649432, 8719722, 9529641, 43208766, 64308654, 64326654
Offset: 1

Views

Author

Klaus Brockhaus, Sep 22 2004

Keywords

Comments

86526432, 64308654, 83208762 form a cycle of length three and 86308632, 86326632, 64326654, 43208766, 85317642, 75308643, 84308652 form a cycle of length seven.

Examples

			53955 and 59994 form a cycle of length 2 and hence are terms: 53955 -> 95553 - 35559 = 59994 -> 99954 - 45999 = 53955.
		

Crossrefs

Cf. A164715 (corresponding cycle lengths) [From Joseph Myers, Aug 24 2009]
In other bases: Empty (base 2), A165000 (base 3), A165019 (base 4), A165039 (base 5), A165058 (base 6), A165078 (base 7), A165097 (base 8), A165117 (base 9). [From Joseph Myers, Sep 05 2009]

Extensions

Definition revised ny N. J. A. Sloane, Aug 18 2009
Extended by Joseph Myers, Aug 22 2009

A090429 3-digit numbers that do not resolve to 495 under the Kaprekar routine.

Original entry on oeis.org

100, 101, 110, 111, 112, 121, 122, 211, 212, 221, 222, 223, 232, 233, 322, 323, 332, 333, 334, 343, 344, 433, 434, 443, 444, 445, 454, 455, 544, 545, 554, 555, 556, 565, 566, 655, 656, 665, 666, 667, 676, 677, 766, 767, 776, 777, 778, 787, 788, 877, 878
Offset: 1

Views

Author

Eric W. Weisstein, Nov 30 2003

Keywords

Crossrefs

Cf. A069746.

A151951 a(1) = 1113; thereafter a(n) = (a(n-1) with digits sorted into descending order) - (a(n-1) with digits sorted into ascending order) (see the Kaprekar map, A151949).

Original entry on oeis.org

1113, 1998, 8082, 8532, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174
Offset: 1

Views

Author

N. J. A. Sloane, Aug 18 2009

Keywords

Crossrefs

Programs

  • Mathematica
    NestList[FromDigits[Reverse[Sort[IntegerDigits[#]]]]-FromDigits[Sort[ IntegerDigits[ #]]]&,1113,40] (* or *) PadRight[{1113,1998,8082,8532},40,{6174}] (* Harvey P. Dale, May 10 2021 *)

A151956 a(1) = 1002; thereafter a(n) = (a(n-1) with digits sorted into descending order) - (a(n-1) with digits sorted into ascending order) (see the Kaprekar map, A151949).

Original entry on oeis.org

1002, 2088, 8532, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174, 6174
Offset: 1

Views

Author

Harvey P. Dale, Aug 18 2009

Keywords

Comments

For the list of fixed points see A099009.

Crossrefs

A160761 The Kaprekar binary numbers in decimal.

Original entry on oeis.org

9, 9, 9, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 45, 45, 49, 45, 49, 49, 45, 45, 49, 49, 45, 49, 45, 45, 45, 49, 49, 45, 49, 45, 45, 49, 45, 45, 45, 93, 93, 105, 93, 105, 105, 105, 93, 105, 105, 105, 105, 105, 105, 93, 93, 105, 105, 105, 105, 105, 105, 93, 105, 105, 105
Offset: 1

Views

Author

Damir Olejar, May 25 2009

Keywords

Examples

			The number 9 is 1001 in binary. The maximum number using the same number of 0's and one's is found and the minimum number having the same number of 0's and 1's is found to obtain the equation such as 1100 - 0011 = 1001. Repeating the same procedure always gives us the same number and pattern of 0's and 1's. Therefore 9 is one of the Kaprekar numbers. Numbers that end the procedure in 0 are excluded since they are not Kaprekar numbers.
		

References

  • M. Charosh, Some Applications of Casting Out 999...'s, Journal of Recreational Mathematics 14, 1981-82, pp. 111-118
  • D. R. Kaprekar, On Kaprekar numbers, J. Rec. Math., 13 (1980-1981), 81-82.

Crossrefs

Programs

  • Java
    class pattern { public static void main(String args[]) { int mem1 = 0; int mem2 =1; for (int i = 1; i<3000; i++) {do { mem1 = mem2; String binaryi = Integer.toBinaryString(i); String binarysort = ""; String binaryminimum = ""; for (int n = 0; n< binaryi.length(); n++) { String g = binaryi.substring(n,n+1); if (g.equals("0")){ binarysort = binarysort+"0"; } else { binarysort = "1"+binarysort; binaryminimum = binaryminimum + "1"; } } int binrev1 = Integer.parseInt(binarysort , 2); int binrev2 = Integer.parseInt(binaryminimum , 2); int diff = binrev1 - binrev2; mem2 = diff; } while (mem2!=0 && mem2!=mem1); String memtobin = Integer.toBinaryString(mem1); int ones = 0; for (int t = 0; t
    				
  • Mathematica
    nmax = 100; f[n_] := Module[{id, sid, min, max}, id = IntegerDigits[n, 2]; min = FromDigits[sid = Sort[id], 2]; max = FromDigits[Reverse[sid], 2]; max - min]; Reap[Do[If[(fpn = FixedPoint[f, n]) > 0, Sow[fpn]], {n, 1, nmax}]][[2, 1]] (* Jean-François Alcover, Apr 23 2017 *)

Formula

1. Sort all integers from the number in descending order 2. Sort all integers from the number in ascending order 3. Subtract ascending from descending order to obtain a new number 4. Repeat the steps 1-3 with a new number until a repetitive sequence is obtained or until a zero is obtained. 5. Call the repetitive sequence's number a Kaprekar number, ignore zeros.
Showing 1-7 of 7 results.