Generalized Kaprekar Routine

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram CDF Player or other Wolfram Language products.

Requires a Wolfram Notebook System

Edit on desktop, mobile and cloud with any Wolfram Language product.

This Demonstration shows fractal patterns in the number of steps required to reach a fixed point or cyclic behavior in an application of Kaprekar's routine applied to the natural numbers for different bases.


To apply the Kaprekar routine for a positive integer greater than 1, arrange the digits of in base in descending () and ascending () order, compute (discarding any initial 0s). Repeating this procedure eventually leads to a cycle or a fixed point. The number of steps required, , plotted as a colored square at the position , produces beautiful fractal patterns. This Demonstration explores a subset of these patterns by allowing the setting of starting values and ranges for and .


Contributed by: Noel Patson (March 2011)
Open content licensed under CC BY-NC-SA




Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.