如何解决我怎样才能解决这个柯克曼的女学生问题?
柯克曼的女学生问题旨在将三个女孩组成一组,持续几天,这样在同一组中,没有一对女孩会在一起超过一次。为此,我与 9 个女孩一起工作,她们需要分成三人一组,为期 4 天。
我对 Python 非常陌生。我现在想避免使用花哨的模块,这样我才能正确地掌握基础知识。
这是我的代码:
prob = ['ariana','barbara','cindy','darlyn','emily','felicia','gwanyth','hilton','india','julie']
same_grps = []
days_arrangement = []
while len(days_arrangement)<=4:
today = []
same_day = []
for i in range(3):
while True:
temp = []
temp_same_day = []
for j in range(3):
for girl in prob:
if girl not in temp_same_day:
temp.append(girl)
temp_same_day.append(girl)
if temp in same_grps:
continue
if temp not in same_grps:
grp = temp[::]
same_grps.append(grp)
today.append(grp)
break
days_arrangement.append(today)
print(days_arrangement)
当我运行它时,内核没有响应,好像陷入了某个无限循环并且没有输出。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。