Created
November 18, 2021 10:46
-
-
Save 0xjgv/092ece63c63312abff0e98faed65e54f to your computer and use it in GitHub Desktop.
Round-robin scheduling algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Inspired from https://en.wikipedia.org/wiki/Round-robin_tournament#Scheduling_algorithm | |
""" | |
team = [ | |
"John", | |
"Lee", | |
"Dave", | |
"Steve", | |
"Louis", | |
"Cindy", | |
] | |
N = len(team) | |
half = N // 2 # divide by two as we want pairs | |
options = [] | |
a, b = team[:half], team[half:] | |
options.append(a + b) | |
for _ in range(N - 2): | |
first_b = b.pop(0) | |
last_a = a.pop() | |
a.insert(1, first_b) | |
b.append(last_a) | |
options.append(a + b) | |
for opt in options: | |
print(opt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment