1955年,卡普耶卡对4位数字进行了研究,发现-一个规律:对任意各位数字不相同的4位数,使用各位数字能组成的最大数减去能组成的最小数,对得到的差重复这个操作,最终会得到6174这个数字,并且这个操作最多不会超过7次。编写程序,使用枚举法对这个猜想进行验证。提示:使用from string importdigits和from itertools import combinations导入digits对象和combinations方法。使用字符串的‘'.join()方法将字符组合成字符串。
参考代码如下,
from string import digits
from itertools import combinationsfor item in combinations(digits, 4):times= 0
while True:
XXXXX
XXXXX