Skip to content

About

In number theory, Kaprekar's routine is an iterative algorithm named after its inventor, Indian mathematician D. R. Kaprekar.[1][2] Each iteration starts with a four-digit random number, sorts the digits into descending and ascending order, and calculates the difference between the two new numbers.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Kaprekar's Constant (6174)

What is Kaprekar's Constant?

Kaprekar's Constant is the number 6174, discovered by Indian mathematician D. R. Kaprekar in 1949. This constant has a fascinating mathematical property when working with 4-digit numbers (with at least two different digits).

The Kaprekar Process

Algorithm Steps:

  1. Take any 4-digit number where not all digits are equal
  2. Arrange digits in descending order (largest possible number)
  3. Arrange digits in ascending order (smallest possible number)
  4. Subtract the smaller number from the larger number
  5. Repeat the process with the result obtained

Practical Example

Let's take the number 3524:

Iteration 1:

  • Descending digits: 5432
  • Ascending digits: 2345
  • Subtraction: 5432 - 2345 = 3087

Iteration 2:

  • Descending digits: 8730
  • Ascending digits: 0378
  • Subtraction: 8730 - 0378 = 8352

Iteration 3:

  • Descending digits: 8532
  • Ascending digits: 2358
  • Subtraction: 8532 - 2358 = 6174

Iteration 4:

  • Descending digits: 7641
  • Ascending digits: 1467
  • Subtraction: 7641 - 1467 = 6174

We've reached the constant!

Important Properties

  • Always converges to 6174 in maximum 7 iterations
  • Works with any 4-digit number (except repdigits like 1111, 2222, etc.)
  • The process cycles once 6174 is reached

Exceptions

The only numbers that don't converge to 6174 are repdigits (numbers with all 4 digits equal):

  • 0000, 1111, 2222, 3333, ..., 9999

Interesting Facts

  • This phenomenon also exists for 3-digit numbers (constant 495)
  • For other digit numbers, the process may enter different cycles
  • It's a fascinating example of "hidden" mathematical properties in numbers

About

In number theory, Kaprekar's routine is an iterative algorithm named after its inventor, Indian mathematician D. R. Kaprekar.[1][2] Each iteration starts with a four-digit random number, sorts the digits into descending and ascending order, and calculates the difference between the two new numbers.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages