用数字 1 到 8 组成两个三位数使其和为 1000,这两个三位数里面的数字不能重复。
问能写几组?
用小学三年级的解题思路还真没想到。
只好用笨方法跑个小程序了。
L=list(range(1,9)) #print(L) s="" S=[] for l in L: for l1 in L: for l2 in L: if str(l)<>str(l1) and str(l)<>str(l2) and str(l1)<>str(l2): s=str(l) + str(l1) + str(l2) S.append(s) def IsSame(a,b): v=True for al in a: for bl in b: if al==bl: v= False return v C1000=[] for c in S: v=1000-int(c) if str(v)[0]<>str(v)[1] and str(v)[0]<>str(v)[2] and str(v)[1]<>str(v)[2] and str(v)[2]<>'9' and IsSame(c,str(v)): C1000.append(c) #print(C1000) #print(len(C1000)) n=1 DisplayList=[] for i in range(len(C1000)/2): DisplayList.append(C1000[i] + " + " + C1000[len(C1000)-n] + " = 1000") n+=1 print(DisplayList)
最终结果有 24 组:
'124 + 876 = 1000', '126 + 874 = 1000', '143 + 857 = 1000', '147 + 853 = 1000', '153 + 847 = 1000', '157 + 843 = 1000', '174 + 826 = 1000', '176 + 824 = 1000', '214 + 786 = 1000', '216 + 784 = 1000', '284 + 716 = 1000', '286 + 714 = 1000', '342 + 658 = 1000', '348 + 652 = 1000', '352 + 648 = 1000', '358 + 642 = 1000', '413 + 587 = 1000', '417 + 583 = 1000', '432 + 568 = 1000', '438 + 562 = 1000', '462 + 538 = 1000', '468 + 532 = 1000', '483 + 517 = 1000', '487 + 513 = 1000'