Skip to content

Instantly share code, notes, and snippets.

@0xjgv
Created November 18, 2021 10:46
Show Gist options
  • Save 0xjgv/092ece63c63312abff0e98faed65e54f to your computer and use it in GitHub Desktop.
Save 0xjgv/092ece63c63312abff0e98faed65e54f to your computer and use it in GitHub Desktop.
Round-robin scheduling algorithm
"""
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