- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我发现了以下内容
Generating natural schedule for a sports league
每次运行它都会生成相同的时间表。如果我在其中添加一个 random.shuffle() ,它仍然太容易预测了。
下面是我对该帖子进行的简单编辑,其中有一个随机位置,我得到了奇怪的结果
import random
def round_robin(units, sets = None):
""" Generates a schedule of "fair" pairings from a list of units """
count = len(units)
sets = sets or (count - 1)
half = count / 2
for turn in range(sets):
left = units[:half]
right = units[count - half - 1 + 1:][::-1]
pairings = zip(left, right)
if turn % 2 == 1:
pairings = [(y, x) for (x, y) in pairings]
units.insert(1, units.pop())
yield pairings
teams = range(5)
random.shuffle(teams)
schedule = list(round_robin(teams, sets = len(teams) * 2 - 2))
for week in schedule:
for game in week:
if 0 in game:
print game
有时似乎球队甚至不会互相比赛..看看结果
(0, 4)
(4, 0)
(0, 2)
(0, 4)
(4, 0)
(0, 2)
我的问题是.. 我怎样才能在 python 中做一个随机计划生成器或修复我已经拥有的东西。
我几乎需要带 4 支球队进行 3 周的比赛,他们之间只打一次比赛。或者像 5 支球队,其中有 5 周的比赛,他们都互相比赛一次,但每周有一支球队被排除在外
最佳答案
我假设每个团队都需要与其他团队一起比赛。不是吗?那这道题不就归结为简单的排列,然后把结果洗牌了吗?
import itertools
import random
set_size = 2
schedule = set()
teams = range(5)
for comb in itertools.product(teams, repeat=set_size):
comb = sorted(list(comb))
if len(set(comb)) == set_size:
schedule.add(tuple(comb))
schedule = list(schedule)
random.shuffle(schedule)
print schedule
关于Python随机运动时间表生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9900839/
我有以下格式的一些数据: 薪水 代码及时 1690 09:03:00 1690 09:13:00 1690 09:07:00 1691 08:48:00 1691 08:52:00 1691 08:5
在基于 jsp 和 servelet 的 Web 应用程序中实现类似 cron 的调度程序的最佳方法是什么?使用“定时器服务”遇到了一个选项。任何其他替代方案或对计时器服务的任何评论? 提前致谢 沙米
好吧,我对 MySQL 和数据库总体来说还很陌生。我想在一段时间后对数据库进行更新。让我解释一下。 所以为了练习,我正在用 php 构建一个游戏,在这个游戏中你将能够升级东西。比如说一栋建筑,从1级升
我想为每个用户创建一个典型的学校时间表。 最终产品应如下所示: +----+---------+---------+-----------+----------+--------+ | h | Mo
我的表格: timetable +----+---------+-------+--------+---------+---------+------+ | id | user_id | s_day
我的网站涉及安排重复类(class)和事件。目前,我已经使用 php 和 javascript 构建了一个表,该表逐个时间段扫描我的 mysql 数据库,每天查看是否有安排的事件或时间段是否空闲。 它
我有一个关于日程安排的问题。我需要为约会制作一个时间表生成器。这是目前的情况。 P1 与 P2 有约会 A。 P3和P4有个约会B。 等等…… 预约 A 大约需要 15 分钟 B约需40分钟 (时长视
我有一个配置如下的 celery 时间表: CELERYBEAT_SCHEDULE = { "runs-every-30-seconds": { "task": "tasks.
我想在“每个月的最后一天 10:15”和“每个月的第一个星期日”运行 spring scheduler 作业 - 我在下面尝试过 - 但它在初始化 spring 上下文时出错: org.springf
如何在运行时检查 openmp 计划? 我使用并行循环和运行时计划编译我的代码 #pragma omp parallel for schedule(runtime) collapse(2) for(j
我已经制作了一个 Android 应用程序,并且它已成功编译,没有任何错误。但是当我在 Android 手机中运行应用程序时,它不会显示所需的输出。 这是我的 MainActivity.java: p
经过一天的痛苦,我终于将数据放入了日程安排事件中。 我现在尝试在单击事件时设置事件,它使用数据变量加载新页面。 这是 xhtml 还有 Java public void redirec
我正在使用 Primefaces Schedule 组件在我的网络应用程序中呈现事件。但我需要对他耍点小花招。对于每个呈现的事件,我需要显示一个包含事件详细信息的工具提示。使用 window.onlo
我想设置一个 crontab 表达式,每 20 分钟启动一次作业,并且它将按照时间表运行 周一至周五上午 7 点至 30 点至晚上 8 点,周六上午 7 点至 30 点至下午 4 点 到目前为止我有以
这是我根据用户输入创建表格的代码: const err = "the valid input is a number between 5 and 20, please refresh your pag
有没有办法在 HighCharts 中制作与此类似的时间线/时间表? https://developers.google.com/chart/interactive/docs/gallery/time
在关于 AES key 表的教程中,我看到 key 表的操作(旋转、rcon、s-box)应用于一个 4 字节的字。你能解释一下这个字从哪里来吗?我明白我从 128 位长的 key 中提取它。 key
SQL Server 作业/时间表 - 美国与英国夏令时调整 我们有一个基于英国的服务器,它需要在 16:30(美国中部时间 - 这可能看起来很奇怪,但这是因为一些数据的可用性)运行 SQL 代理作业
我有一个 quartz 作业,每天下午 3 点(服务器时间)运行。我想做的是让它在下午 3 点运行,但针对美国的每个时区。 quartz 作业会触发一封电子邮件给我的用户,我希望每个人都能在他们的时间
我想以一种非常简单的方式展示电视指南时间线,但我对此真的很陌生,所以我希望有人可以帮助我,我不想要太复杂的东西,而且我已经在网络上搜索并且我发现非常复杂的时间线,有很多我真的不需要的功能,我只想显示当
我是一名优秀的程序员,十分优秀!