Last active
April 3, 2023 23:01
-
-
Save dhruvilp/a2774c47a48edd42c2ee9f68cafdf67e to your computer and use it in GitHub Desktop.
Team formation
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
import random | |
participants = [i for i in range (1,41)] | |
random.shuffle(participants) | |
groups = [participants[i:i+4] for i in range(0, len(participants), 4)] | |
for i in range(len(groups)): | |
print(f"Group {i+1}: {groups[I]}") | |
# Create a list of numbers from 1 to 10 | |
numbers = list(range(1, 11)) | |
# Initialize a dictionary to keep track of the counts | |
counts = {num: 0 for num in numbers} | |
# Initialize a list to store the sets of 2 numbers | |
number_sets = [] | |
# Loop until each number has been picked at least 4 times across all sets | |
while any(count < 4 for count in counts.values()): | |
# Pick 2 random numbers from the list of numbers | |
num1, num2 = random.sample(numbers, 2) | |
# Check if both numbers have been picked less than 4 times | |
if counts[num1] < 4 and counts[num2] < 4: | |
# Add the set of numbers to the list and update the counts | |
number_sets.append((num1, num2)) | |
counts[num1] += 1 | |
counts[num2] += 1 | |
# Print the list of sets of numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment