我正在寻找一种方法来生成所有可能的场景的列表,其中18张卡可以分配给6个玩家。然后,我想遍历列表并删除所有符合特定条件的实例。
我正在研究一种算法,可以帮助我预测信封中的卡片。我想找出所有可能的场景列表,在这些场景中可以将卡分配给所有六个玩家。
例如,对于18张卡片的列表,看起来像这样
master_list =list (['w1','w2','w3',....,'l9'])
我想要这样的输出
[[['player 1' 'w1' 'w2' 'l1']
['player 2' 'w3' 's1' 's2']
['player 3' 'l2' 'l3' 's3']
['player 4' 'l4' 's5' 's4']
['player 5' 'w4' 'l5' 'l6']
['player 6' 'w5' 'l7' 'l8']]
[['player 1' 'w5' 'w2' 'l1']
['player 2' 'w4' 's1' 's2']
['player 3' 'l4' 'l3' 's3']
['player 4' 'l2' 's5' 's4']
['player 5' 'w3' 'l5' 'l6']
['player 6' 'w1' 'l7' 'l8']]
....
.... all the possible scenarios
这是我到目前为止所做的。。
导入所有必需的库
import itertools import numpy as np from itertools import combinations import operator as op from functools import reduce #master_list = list of all the cards #new_master = list of all the cards left after i reveal my cards #comb = all possible combinations based on new_master list #pos_env_comb = all possible candidates for envelope
从玩家1输入,然后从主列表中删除这些卡并创建新的主列表
print("input your cards with spaces") input_list = [str(x) for x in input().split()] master_list = list(['w1','w2','w3','w4','w5','w6',....,'l8','l9']) new_master = np.setdiff1d(master_list,input_list) print(new_master) pos_env_comb = list()
创建信封中所有可能的组合
comb = list(combinations(new_master, 3))
print(len(comb))
# Print the obtained combinations
for i in comb:
w = 0
s = 0
l = 0
c = 0
for j in i:
if(j[0][0] == 'w'):
w = w + 1
elif(j[0][0] == 's'):
s = s + 1
else:
l = l + 1
if(w == 1 and s == 1 and l == 1):
pos_env_comb.append(i)
print(len(pos_env_comb))
我正在寻找一种方法来生成所有可能的场景的列表,其中18张卡可以分配给6个玩家。然后,我想遍历该列表并删除所有......>
(18 choose 3) * (15 choose 3)* (12 choose 3)* (9 choose 3)* (6 choose 3)* (3 choose 3) = 137225088000 = 1.37225088 * 10^11