How I hacked scheduling class meetings

As a preface, I think this merits the label hack not because it’s particularly clever or well-implemented; simply it was the fastest way for me to arrive at an optimal solution for a well-defined problem.

Problem statement

Splitting a class of $$k$$ students into $$n$$ disjoint meetings (‘sections’) which meet once a week on a pre-determined day of the week, and finding a mutually convenient time for each session based on the availability of each student

Solution

  1. Represent the availabilty of the students at each one of the $$m$$ hours in the day as a vector (length $$k$$) of truthy values
  2. Notice that binary numbers are basically vectors of truth values
  3. Perform a recursive bitwise OR on each of the $$m \choose n$$ choices of binary numbers which each represent the group’s availability at precisely one of the hours in the day
  4. Get the Hamming weight (number of bits set) of each result
  5. Order the $$m \choose n$$ choices by their associated Hamming weight
  6. The choices of times for the $$n$$ section meetings with maximum weight suit the greatest number of students!

Implementation

I implemented this for $$n = 2$$ because that’s what I needed at the time. See here for a rubbish implementation.