Hacker News new | ask | show | jobs
by shou4577 5491 days ago
In fact, it says that 6174 is more than just a fixed point, it is also the only fixed point, and an attracting fixed point. That is, every four digit number with transform to 6174 in finite (indeed, less than 7) steps under Kaprekar's operation.

This is significantly stronger than just being a fixed point. As an analogy, when modeling population dynamics, one often finds both stable and non-stable equilibrium solutions. The stable ones are the only solutions that can occur in nature, and so their stability is an important thing to note. This stability often (I hesitate to say always) is the result of the solution having the same attractive nature as 6174 does.

1 comments

Another fixed point of the operation is zero, which is reached in a single step if you start with a number with all the same digits (1111, for example.) Zero is stable and attracting, it just has a very small basin of attraction.
If you want to see precisely which numbers lead to which fixed points, and in how many steps, I've posted it here for all 4-digit numbers:

http://pastebin.com/3iXT777N

Here's a plot: http://imageshack.us/f/192/stepsd.png/

It might be interesting to plot the mapping instead.

edit: one has already been made: http://news.ycombinator.com/item?id=2626879

Thanks, but there's a bug in your code/results - for example, 1011 does not converge to 0, it does hit 6174 in 5 steps. Only 1111, 2222, etc. yield 0.

I suspect the handling of 3-digit values. I also slipped there at first ;-)

For 1011, the next step is 1110 - 0111 = 999, and then... apparently you're supposed to handle that as 9990 - 0999, rather than 999 - 999. Huh. I see.

But I'm inclined to consider that a bug in the definition, rather than in the code. :-} The four-digit-ness came from applying the operation to four-digit numbers, and saying "oh yeah and we'll zero-extend the results to four digits" introduces an ugly element of redundancy.

However, we can make it not ugly anymore by making "zero-extend everything to make it be 4 digits" the primary condition. Instead of applying it to 4-digit numbers, we'll make every number have 4 digits and then apply the Kaprekar procedure. So we'll now be working with the numbers 0000-9999, rather than 1000-9999. (There's no way to zero-extend numbers bigger than 9999 to be 4 digits, so that's all.) Here are the results for 0000-9999:

http://pastebin.com/TQ3cMshV

I think the frequencies of the number of steps to equilibrium are somewhat nicer, as well, when you count 0000-0999. As a simple metric, they have more factors of small primes, especially 2.

  1000-9999:
  0 steps:    1 =   1
  1 steps:  365 =   5 *  73
  2 steps:  519 =   3 * 173
  3 steps: 2124 = 2^2 * 3^2 *  59
  4 steps: 1124 = 2^2 * 281
  5 steps: 1379 =   7 * 197
  6 steps: 1508 = 2^2 *  13 *  29
  7 steps: 1980 = 2^2 * 3^2 *   5 *  11

  0000-9999:
  0 steps:    2 =   2
  1 steps:  392 = 2^3 * 7^2
  2 steps:  576 = 2^6 * 3^2
  3 steps: 2400 = 2^5 *   3 * 5^2
  4 steps: 1272 = 2^3 *   3 *  53
  5 steps: 1518 =   2 *   3 *  11 *  23
  6 steps: 1656 = 2^3 * 3^2 *  23
  7 steps: 2184 = 2^3 *   3 *   7 *  13