好友
阅读权限10
听众
最后登录1970-1-1
|
要找出所有可以组合的三带一或者三带二的牌型,你可以使用递归的方法来解决。下面是一个Python示例代码,用于生成所有可能的三带一或者三带二的组合:
```python
def find_combinations(cards, n, combo_length):
combinations = []
if combo_length == 2:
# 找出所有的三带二组合
for i in range(len(cards)):
for j in range(i+1, len(cards)):
for k in range(j+1, len(cards)):
for l in range(len(cards)):
if l != i and l != j and l != k:
combinations.append([cards[i], cards[i], cards[i], cards[j], cards[k]])
elif combo_length == 1:
# 找出所有的三带一组合
for i in range(len(cards)):
for j in range(i+1, len(cards)):
for k in range(j+1, len(cards)):
for l in range(len(cards)):
if l != i and l != j and l != k:
combinations.append([cards[i], cards[i], cards[i], cards[l]])
else:
# 递归生成更长的组合
for i in range(len(cards)):
rest_cards = cards[:i] + cards[i+combo_length-1:]
sub_combinations = find_combinations(rest_cards, n-1, combo_length)
for sub_combination in sub_combinations:
combinations.append([cards[i]] * combo_length + sub_combination)
return combinations
# 示例输入
cards = [5, 5, 5, 7, 7, 7, 6, 6, 6, 'J', 'Q', 'Q', 'K', 'K']
combo_length = 4
# 调用函数查找所有组合
combinations = find_combinations(cards, len(cards), combo_length)
# 输出结果
for combination in combinations:
print(combination)
```
这段代码将根据输入的牌列表 `cards` 和组合长度 `combo_length`,生成所有可能的三带一或者三带二的组合。请注意,这个代码示例假设输入的牌列表已经包含了所有可以组合的三张牌和可用于组合的其他牌。输出结果将打印在控制台上,你可以根据需要进行进一步处理或调整输出格式。 |
|