Search for a tool
Kaprekar Algorithm

Tool using the Kaprekar algorithm. It uses an integer N, and arranges its digits in ascending and descending order, before subtracting them.

Results

Kaprekar Algorithm -

Tag(s) : Arithmetics, Algorithm

Share
Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best 'Kaprekar Algorithm' tool for free! Thank you!

Kaprekar Algorithm

Calculus through Kaprekar Algorithm


Answers to Questions (FAQ)

How to calculate Kaprekar sequence?

The Kaprekar routine from a number $ N $ consists of creating 2 other numbers $ N_1 $ and $ N_2 $ by arranging the digits of $ N $ through sorting by ascending order to $ N_1 $ and decreasing for $ N_2 $. Kaprekar then forms a new number $ N $ such that $ N_2-N_1 = N $ and repeats the process until arriving at a previously found number.

Example: $ N = 7533 $, $ N_1 = 3357 $, $ N_2 = 7533 $, replace $ N $ with $ 7533 - 3357 = 4176 $
$ N = 4176 $, $ N_1 = 1467 $, $ N_2 = 7641 $ then replace $ N $ with $ 7641 - 1467 = 6174 $
$ N = 6174 $, $ N_1 = 1467 $, $ N_2 = 7641 $ replace $ N $ with $ 7641 - 1467 = 6174 $, which creates an infinite loop on the constant 6174, which is the Kaprekar constant for 4 digits.

What are Kaprekar constants and Kaprekar loops?

Loops are repetition of values or constants that appears in the algorithm depending on the size of the number $ N $.

Number of digitsConstant/Loop
3495
46174
553955, 59994 or 62964, 71973, 83952, 74943 or 61974, 82962, 75933, 63954
6420876, 851742, 750843, 840852, 860832, 862632, 642654 or 631764 or 549945
77509843, 9529641, 8719722, 8649432, 7519743, 8429652, 7619733, 8439552
843208766, 85317642, 75308643, 84308652, 86308632, 86326632, 64326654 or 64308654, 83208762, 86526432 or 97508421 or 63317664

When one of these numbers is reached, either it remains constant or it follows the cycle by looping to infinity.

How to prove that 6174 is the only 4-digit Kaprekar constant?

The mathematical proof of the existence of 6174 as the only fixed point number of the algorithm is a bit long and consists in enumerating a few possible cases and proving that only one case has no contradiction. The proof: here

Source code

dCode retains ownership of the "Kaprekar Algorithm" source code. Except explicit open source licence (indicated Creative Commons / free), the "Kaprekar Algorithm" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or the "Kaprekar Algorithm" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and all data download, script, or API access for "Kaprekar Algorithm" are not public, same for offline use on PC, mobile, tablet, iPhone or Android app!
Reminder : dCode is free to use.

Cite dCode

The copy-paste of the page "Kaprekar Algorithm" or any of its results, is allowed (even for commercial purposes) as long as you credit dCode!
Exporting results as a .csv or .txt file is free by clicking on the export icon
Cite as source (bibliography):
Kaprekar Algorithm on dCode.fr [online website], retrieved on 2024-12-21, https://www.dcode.fr/kaprekar-algorithm

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'Kaprekar Algorithm' tool for free! Thank you!


https://www.dcode.fr/kaprekar-algorithm
© 2024 dCode — The ultimate 'toolkit' to solve every games / riddles / geocaching / CTF.
 
Feedback