Skip to content

Instantly share code, notes, and snippets.

@hannal
Created May 14, 2023 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannal/360542e731e03ddd4f4bb1cc37e2a137 to your computer and use it in GitHub Desktop.
Save hannal/360542e731e03ddd4f4bb1cc37e2a137 to your computer and use it in GitHub Desktop.
from itertools import combinations
from math import factorial
def count_combinations(n: int, r: int):
return int(factorial(n) / (factorial(r) * factorial(n-r)))
team_count = 4
# 0 1 2 3 4 5 6 7 8 9 10 11
people = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]
result = tuple(combinations(people, team_count))
total = count_combinations(len(people), team_count) # same as `len(result)`
# 1
comb1 = result[0] # a, b, c, d
# 2
index1 = count_combinations(len(people)-1, team_count-1)
index2 = count_combinations(len(people)-4, team_count-1) # 4 == 'e' index
comb2 = result[index1-index2] # a, e, f, g
# 3
index1 = count_combinations(len(people)-1, team_count-1)
index2 = count_combinations(len(people)-7, team_count-1) # 7 == 'h' index
comb3 = result[index1-index2] # a, h, i, j
@hannal
Copy link
Author

hannal commented Sep 4, 2023

test comment

@hannal
Copy link
Author

hannal commented Sep 6, 2023

Screenshot 2023-08-30 at 11 26 21

test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment