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!

This page is using the new English version of dCode, please make comments !

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

Answers to Questions

How to calculate Kaprekar sequence?

Kaprepar routine consists in forming integers N1, respectively N2, by arranging digits in ascending, respectively descending order. It forms then N = N2-N1 and repeat the process until a previous number is found.

N = 7533, N1 = 3357, N2=7533, one replace N by 7533-3357=4176 N = 4176, N1 = 1467, N2=7641, one replace N by 7641-1467=6174 N = 6174, N1 = 1467, N2=7641, one replace N by N=7641-1467=6174, there is a loop on constant 6174, called Kaprekar Constant.

What are Kaprekar constants and Kaprekar loops?

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

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

Ask a new question

Source code

dCode retains ownership of the source code of the script Kaprekar Algorithm. Except explicit open source licence (free / freeware), any algorithm, applet, software (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any snippet or function (convert, solve, decrypt, encrypt, decipher, cipher, decode, code, translate) written in PHP (or Java, C#, Python, Javascript, etc.) which dCode owns rights can be transferred after sales quote. So if you need to download the Kaprekar Algorithm script for offline use, for you, your company or association, see you on contact page !

dCode uses cookies to customize the site content, analyze user behavior and adapt dCode to your use. Some data is stored and collected for advertising purposes and may be shared with our partners. OK