kirby urner wrote:
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.
...
Here's one way to test the result. Think of a different way?
def counts(limit=7, closer=6174):
counts = [0] * limit
exceptions = set()
for ournum in range(10000):
start = quad = ''.join(sorted('%04d' % ournum))
if quad[0] == quad[3] or quad in exceptions:
continue
for distance in range(limit):
diff = int(''.join(reversed(quad))) - int(quad)
if diff == closer:
break
quad = ''.join(sorted('%04d' % diff))
else:
exceptions.add(start)
counts[distance] += 1
return counts, sorted(exceptions)
-Scott
_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig