Skip to content

Instantly share code, notes, and snippets.

@earthling-shruti
Created January 30, 2013 01:39
Show Gist options
  • Save earthling-shruti/4669848 to your computer and use it in GitHub Desktop.
Save earthling-shruti/4669848 to your computer and use it in GitHub Desktop.
def tourney(N, C):
if N < 2 or C < 1:
print "Enter >2 N and >0 C"
sys.exit()
#generate game set
game_set = []
for i in range(1, N):
for j in range(i+1, N+1):
game_set.append(str(i) + " vs " + str(j))
#total number of games
num_games = math.factorial(N) / (2* math.factorial(N-2))
i = 0
time = 1
if C <= (N/2):
while i < num_games:
for c in range(C):
if i < num_games:
print time,
print game_set[i]
i += 1
time += 1
else:
while i < num_games:
for c in range(N/2):
if i < num_games:
print time,
print game_set[i]
i += 1
time +=1
tourney(6,4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment