首页 > 代码库 > 小学题的python实现

小学题的python实现

用1-8八个数字不重复使用,组成两个四位数,其中一个是另一个的四倍。

 

#encoding:utf8from itertools import *def delSrc(i, l):	l.pop(l.index(i))	return ldef makeStr(l):        s = ""        for i in l:            s += str(i)        return sif __name__ == ‘__main__‘:    num = [1,2,3,4,5,6,7,8]    for i in combinations(num, 4):        l = num        for j in i:        	l = delSrc(j,list(l))        str1, str2 = makeStr(i), makeStr(l)        p, q = list(permutations(str1)), list(permutations(str2))        for m in p:            for n in q:                s1,s2 = "",""                for a, b in zip(m,n):                    s1 +=a                    s2 +=b                if int(s1) == 4 * int(s2) or int(s2) == int(s1):                    print s1, s2

 

  

  

小学题的python实现