python刷题之路

python刷题之路

题目:两个乒乓球队进行比赛,各出三人。甲队为 a,b,c 三人,乙队为 x,y,z 三人。已
抽签决定比赛名单。 有人向队员打听比赛的名单。 a 说他不和 x 比,c 说他不和 x,z 比,
请编程序找出三队赛手的名单

import random
from pprint import pprint
import pandas as pd
A=[‘a’,‘b’,‘c’]
B=[‘x’,‘y’,‘z’]
rules=[(‘a’,‘x’),(‘c’,‘x’),(‘c’,‘z’)]
final=[]
a=0
def make_possible_list():
possibles = []
a=0
while 1:
A_n = random.choice(A)
B_n = random.choice(B)
cur=(A_n,B_n)
if cur !=a:
if cur not in possibles:
if (cur!=rules[0]) and (cur!=rules[1] and cur!=rules[-1]):
possibles.append(cur)
print(cur)
z=[j[0] for j in possibles]
e=[j[1] for j in possibles]
if ((‘a’ in z )and (‘b’ in z )and (‘c’ in z) )and ((‘x’ in e) and(‘y’ in e)and(‘z’ in e)):
return possibles # continue
a = cur
else:
print(‘keep searching’)
continue

###[(‘a’, ‘z’), (‘b’, ‘x’), (‘a’, ‘y’), (‘b’, ‘z’), (‘b’, ‘y’), (‘c’, ‘y’)]
final=[]
while 1:
li=make_possible_list()
final.append(li)
if len(final)==8000:
break
pprint(pd.Series(final).map(lambda x:str(x)).unique())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值