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

Kaprekar Algorithm - dCode

Tag(s) : Mathematics, Algorithm

dCode is free and its tools are a valuable help in games, puzzles and problems to solve every day!

You have a problem, an idea for a project, a specific need and dCode can not (yet) help you? You need custom development? *Contact-me*!

Sponsored ads

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

The Kaprekar routine from a number \( N \) consists of creating 2 other numbers \( N_1 \) and \( N_2 \) by arranging the digits of \( N \) in 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 a loop on the constant 6174, called the Kaprekar constant.

Loops are repetition of values or constants that appears in the algorithm.

Number of digits | Constant/Loop |
---|---|

3 | 495 |

4 | 6174 |

5 | 53955, 59994 or 62964, 71973, 83952, 74943 or 61974, 82962, 75933, 63954 |

6 | 420876, 851742, 750843, 840852, 860832, 862632, 642654 or 631764 or 549945 |

7 | 7509843, 9529641, 8719722, 8649432, 7519743, 8429652, 7619733, 8439552 |

8 | 43208766, 85317642, 75308643, 84308652, 86308632, 86326632, 64326654 or 64308654, 83208762, 86526432 or 97508421 or 63317664 |

dCode retains ownership of the source code of the script Kaprekar Algorithm online. Except explicit open source licence (indicated Creative Commons / free), any algorithm, applet, snippet, software (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any function (convert, solve, decrypt, encrypt, decipher, cipher, decode, code, translate) written in any informatic langauge (PHP, Java, C#, Python, Javascript, Matlab, etc.) which dCode owns rights will not be given for free. So if you need to download the online Kaprekar Algorithm script for offline use, check contact page !

kaprekar,constant,algorithm,routine,495,6174,digit,number,sort,order,sequence

Source : https://www.dcode.fr/kaprekar-algorithm

© 2018 dCode — The ultimate 'toolkit' to solve every games / riddles / geocaches. dCode