|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 akai735 于 2021-10-26 19:42 编辑
太暴力了有没有简洁点的办法
如果是指定的数字不是又要在写一个
nsum=[2,5,9,11,15,16,18,22,25,26,30,35,36,39,44,45,47,49,52,55,56,61,64,68,72,75,80]
n=int(input("复试:"))
list_2=[]
list_1=[]
print('共计:',len(nsum),'码')
mum=1
while mum<len(nsum):
x=0
while x<10000:
list_3=[]
for i in nsum:
if len(nsum)==n:
b=nsum[:]
list_1.append(b)
nsum.pop(0)
elif len(nsum)<n:
b=nsum.pop(0)
list_2.append(b)
elif len(list_3)<n:
list_3.append(i)
elif list_3 not in list_1:
list_1.append(list_3)
b=nsum.pop(1)
list_2.append(b)
continue
x=x+1
l=1
while l<10000:
list_3=[]
for j in list_2:
if len(list_2)==n:
b=list_2[:]
list_1.append(b)
list_2.pop(0)
elif len(list_2)<n:
b=list_2.pop(0)
nsum.append(b)
elif len(list_3)<n:
list_3.append(j)
elif list_3 not in list_1:
list_1.append(list_3)
b=list_2.pop(1)
nsum.append(b)
continue
l=l+1
mum=mum+1
print('共计组:',len(list_1))
for exte in list_1:
print(exte)
arr = [2, 5, 9, 11, 15, 16, 18, 22, 25, 26, 30, 35, 36, 39, 44, 45, 47, 49, 52, 55, 56, 61, 64, 68, 72, 75, 80]
size = 9; res = []; temp = None
for n, i in enumerate(arr):
temp = [i]
for j in range(n+1, len(arr)-7):
res.append(temp + arr[j:j+8])
print(f"复试:{size}\n共计:{len(arr)}\n共计组:{len(res)}")
for i in res:
print(i)
|
-
|