Automagic sorting

Hi, I’m new to Airtable. I am working on a project that will require automatic sorting and grouping of registrants. Below is an example of my problem.

  1. An event is created by a host and sets is a limit to the number of participants in a class
  2. Users register for an event.
  3. On the day of the event, the host verifies attendance, and the classes that exceed the limit must be divided into heats. (this is intended for a competition)

How do I do part 3?

I envision a way to divide groups that exceed the limit until the groups are below the limit. But, I don’t know the best way to do this.

Limit = 5
In attendance = 34

In this example, I am left with 6 heat of 5 and 1 heat of 4. This is good.

Limit = 5
In attendance = 36

In this example, I am left with 7 heat of 5 and 1 heat of 1. This is bad. One person in a heat isn’t much of a competition.

Aside from the math, I’m not sure that this can be done in Airtable.

Any suggestions?