2008-03-14

I hate mathematics

Via Gary King, I found this little weirdness, called the 6174 problem.

  1. Pick any four distinct digits (e.g., 6, 2, 9, 0)
  2. arrange them into the largest possible integer (e.g., 9620)
  3. arrange them into the smallest (e.g., 0269)
  4. subtract the smaller from the larger (e.g., (- 9620 0269) => 9351)
  5. go back to step 2 and repeat
The cool thing is that, regardless of which digits you choose, you will end up with 6174. Here's the sequence for the digits 6, 2, 9, 0:
9620 - 0269 = 9351
9531 - 1359 = 8172
8721 - 1278 = 7443
7443 - 3447 = 3996
9963 - 3699 = 6264
6642 - 2466 = 4176
7641 - 1467 = 6174
7641 - 1467 = 6174 ...
Apparently that's the longest one, I haven't bothered to check myself but I did translate Gary's Lisp code to Python. I took the memoize implementation straight from the Python Decorator Library. The whole thing is about 100 lines (which includes doctests).

1 kommentar:

woolfel sa...

david copperfield did this trick on TV back in the 90's. it is a pretty neat trick for kids and makes them go WOW.