[Edu-sig] Mystery Number 6174
kirby urner
kirby.urner at gmail.com
Sun Jul 6 20:36:12 CEST 2008
Yutaka Nishiyama has this interesting article in the March 2006 issue
of Plus, entitled 'Mysterious number 6174'.
The theorem in this article is as follows: any 4-digit positive
integer, stipulating all 4 digits *not* be the same one, may be
distilled to 6174 by the following
process: extract the largest and smallest two integers from the 4
digits and subtract the smaller from the larger, and repeat as
necessary.
>>> funtopic.converge()
2283: 8322 - 2238 == 6084
6084: 8640 - 0468 == 8172
8172: 8721 - 1278 == 7443
7443: 7443 - 3447 == 3996
3996: 9963 - 3699 == 6264
6264: 6642 - 2466 == 4176
4176: 7641 - 1467 == 6174
>>> funtopic.converge()
9822: 9822 - 2289 == 7533
7533: 7533 - 3357 == 4176
4176: 7641 - 1467 == 6174
>>> funtopic.converge()
6685: 8665 - 5668 == 2997
2997: 9972 - 2799 == 7173
7173: 7731 - 1377 == 6354
6354: 6543 - 3456 == 3087
3087: 8730 - 0378 == 8352
8352: 8532 - 2358 == 6174
Here's one way to test the result. Think of a different way?
def somenum(n = 4):
digits = range(10)
ans = []
good = False # no exit pass (yet)
while True:
for i in range(n):
ans.append(choice(digits)) # pick any n digits
firstdigit = ans[0]
# not much chance all digits the same
# compare first to rest, pass test on first
# exception
for i in range(1,n+1):
if firstdigit != ans[i]:
good = True # exit pass
break
if good: break # has exit pass
return "".join([str(i) for i in ans])
def converge(closer = 6174):
ournum = somenum()
while True:
smallest = sorted(list(ournum))
highest = reversed(smallest)
strhi, strlo = "".join(highest), "".join(smallest)
diff = int(strhi) - int(strlo)
print( "%s: %s - %s == %s" % (ournum, strhi, strlo, diff) )
if diff == closer: return
ournum = str(diff)
Kirby
Related reading:
http://controlroom.blogspot.com/2007/01/aguirre-wrath-of-god-movie-review.html
More information about the Edu-sig
mailing list