Problem 68. Kaprekar Steps
6174 is the Kaprekar constant. All natural numbers less than 10,000 (except some with same digits) can be reduced to 6174 in the following steps:
Order the digits of the number in descending and ascending order and compute the difference. Repeat the process till you get 6174.
n = 2376
Digits in descending order = 7632
Digits in ascending order = 2367
Total number of steps = 5.
Your function should return the number of Kaprekar steps for a given input. Numbers such as 2222 will end in zero. These numbers will never result in 6174. They should return Inf.
Solution CommentsShow comments
Problem Recent Solvers2081