Welcome to Musical Chairs

The Algorithm

The algorithm is implemented in four different ways. The basic idea is to sort the guests by their total number of friends. Then, starting with the guest with the most friends, assign them a seat at the table and remove them and all of their friends from the list of guests. Repeat this process until there are no guests remaining. The different implementations of the algorithm differ in how the guests are sorted.

Using a Class

The first implementation uses a class to represent the guests. The class has two attributes: the total number of friends and a list of the guest's friends. The class also has a method to calculate the total number of friends and a method to remove a guest and all of their friends from a list of guests.

Using Python's heapq Module

The second implementation uses Python's heapq module to sort the guests by their total number of friends. The heapq module is a priority queue implementation. It is used here to sort the guests by their total number of friends in descending order. This approach requires that the guests be represented as a list of tuples containing the total number of friends and the list of friends.

Using Standalone Functions

The third implementation uses standalone functions to sort the guests by their total number of friends. The first function calculates the total number of friends for a given guest. The second function sorts the guests by their total number of friends in descending order. This approach requires that the guests be represented as a list of tuples containing the total number of friends and the list of friends.

Using Python's zip Function

The fourth implementation uses Python's zip function along with the built-in sorted function to sort the guests by their total number of friends. The zip function takes two lists and returns a list of tuples containing the corresponding elements of each list. The sorted function takes a list of tuples and sorts them by the first element of each tuple. This approach requires that the guests be represented as two lists: one containing the total number of friends and the other containing the list of friends.


About

This is a project by Thomasthaddeus. You can find more details in the README.

Directory Structure