Team USA formation

Background

8 students will represent the U.S. for the 2025 IOAI. Beyond the two-round individual tests that will determine each individual’s ranking and medal, there will also be a team challenge component. 8 students will form two teams for the team challenge.

To make the team formation fair, fun and AI-flavored, we implemented the following algorithm to divide 8 students into 2 teams:

Team formation algorithm

Each of you should generate a random NumPy array with shape (512,). Please save it in the format of “FirstName.npy”.

We will run the following algorithm to compute your cosine similarity with everyone and then sort them in an increasing order.

Those whose rankings are 0, 2, 4, 6 will be in one team, and those whose rankings are 1, 3, 5, 7 will be in another team.

from google.colab import drive
drive.mount('/content/drive')

import os
import numpy as np

# Path to your folder (adjust if needed)
folder_path = 'replace with your own path'


# Dictionary to store loaded arrays
npy_data = {}

# Iterate over all .npy files
for file_name in os.listdir(folder_path):
    if file_name.endswith('.npy'):
        file_path = os.path.join(folder_path, file_name)
        key = os.path.splitext(file_name)[0]  # use filename without extension as key
        npy_data[key] = np.load(file_path)

# Check that everyone made a correct submission

for key, array in npy_data.items():
    print(key)
    print(type(array))
    print(array.shape)

# Stack everyone's submission to a NumPy array with shape (num_contestants,512)

data = np.stack(list(npy_data.values()), axis=0)
print(data.shape)

# Stack contestant names to a NumPy array with shape (num_contestants,)

names = np.stack(list(npy_data.keys()), axis=0)
print(names.shape)

# Print each contestant's index and name

for i, name in enumerate(names):
    print(f"Index: {i}, Name: {name}")

# Team formation algorithm

def team(data, names): # data is a NumPy array with shape (num_contestants,512), names is a NumPy array with shape (num_contestants,)
    data_norm = np.linalg.norm(data, axis=1)
    sim = np.sum(data[:,None] * data, axis=-1) / (data_norm[:,None] * data_norm)
    print(f"Similarity matrix: \n {sim}") # Print the similarity matrix

    sim_avg = np.mean(sim, axis=1) # Compute each contestant's average similarity score
    print(f"Individual average similarity scores before sorting: \n {sim_avg}")

    sorted_indices = np.argsort(sim_avg)[-1::-1].reshape(4,2) # Sorted indices (decreasing order)
    print(f"Sorted indices (decreasing order): \n {sorted_indices}")
    print(f"Rankings after sorting similarity scores: \n {names[sorted_indices.reshape(-1)]}")

    for team in range(2):
        print(f"Team {team+1} members are: \n {names[sorted_indices[:,team]]}")

# Run the algorithm

team(data, names)