I hate mathematics
Via Gary King, I found this little weirdness, called the 6174 problem.
- Pick any four distinct digits (e.g., 6, 2, 9, 0)
- arrange them into the largest possible integer (e.g., 9620)
- arrange them into the smallest (e.g., 0269)
- subtract the smaller from the larger (e.g., (- 9620 0269) => 9351)
- go back to step 2 and repeat
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).9620 - 0269 = 9351
9531 - 1359 = 8172
8721 - 1278 = 7443
7443 - 3447 = 3996
9963 - 3699 = 6264
6642 - 2466 = 41767641 - 1467 = 6174
7641 - 1467 = 6174
...
1 kommentar:
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.
Skicka en kommentar