Allocate limited places on elective courses from an input.json of courses (with caps), a per-student maxCourses limit and timestamped requests, producing enrolments.csv and course-fill.json. Use whenever the user asks to allocate, enrol, waitlist or process course requests with caps, year-of-study priority, request times, or a maximum number of courses per student, even if they do not name the files.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Enrolment Caps?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/gabrielmoreira-enrolment-caps-e0c6c3f9)
---
name: enrolment-caps
description: Allocate limited places on elective courses from an input.json of courses (with caps), a per-student maxCourses limit and timestamped requests, producing enrolments.csv and course-fill.json. Use whenever the user asks to allocate, enrol, waitlist or process course requests with caps, year-of-study priority, request times, or a maximum number of courses per student, even if they do not name the files.
---
# enrolment-caps
You cannot run code, so do this by careful hand-simulation, writing your working to a scratch file so nothing is lost. Accuracy matters more than speed: one misordered request changes who gets a place.
## Input (input.json, in the working folder)
- `maxCourses`: whole number, the most enrolled places one student may hold.
- `courses`: array of `{code, cap}`.
- `requests`: array of `{student, year, course, at}`; `at` is "HH:MM" 24-hour.
Student IDs and course codes are case-sensitive: `s1` and `S1` are different students, `his210` and `HIS210` different courses. Never normalise them.
## Step 1: Drop repeat requests
Group requests by the pair (student, course). Keep only the one with the earliest `at`; discard the others entirely (they appear nowhere in any output). Choose by time, not by position in the file. Compare times as minutes (HH*60+MM), or as zero-padded strings.
## Step 2: Sort the surviving requests into priority order
1. Year descending (3, then 2, then 1), regardless of time.
2. Within a year, `at` ascending.
3. Same year and same time: student ID ascending in ASCII/byte order (digits < uppercase < lowercase; so `Z9` comes before `a1`, and `S10` before `S2`; a shorter string that is a prefix of a longer one comes first). Do not use natural or case-insensitive ordering.
Write the sorted list out as numbered lines in the scratch file before processing.
## Step 3: Handle requests one at a time in that order
Keep these tallies: for each student, `held` (enrolled places); for each course, `enrolled` and `waitlisted` counts. For each request:
1. If student's `held` >= `maxCourses`: status `limit`, place empty. Nothing else changes; they do NOT join the waiting list, even if the course is full. (If maxCourses is 0 everyone is `limit`.)
2. Else if course `enrolled` < `cap`: status `enrolled`, place empty; increment student's `held` and the course's `enrolled`.
3. Else: status `waitlisted`; course `waitlisted` += 1 and place = that new value (1 for first to join, 2 for next...). `held` is unchanged — waiting-list places never count toward maxCourses. (A cap of 0 means every non-limit request is waitlisted.)
Nobody is ever promoted off a waiting list; places are fixed once given. A student who is `limit` on a course takes no place there, so it does not change that course's counts.
Record each result row as (course, student, status, place) in handling order.
## Step 4: Write enrolments.csv (beside input.json)
- First line exactly: `course,student,status,place`
- One row per surviving request (including `limit` rows).
- Group rows by course, courses in ascending ASCII order of code (uppercase before lowercase, digits before letters). Within a course keep the Step 3 handling order (do not re-sort by student). Courses with no rows add nothing.
- `place` is the number for `waitlisted`, and an empty field for `enrolled` and `limit` (the row ends with a trailing comma, e.g. `HIS210,s1,enrolled,`).
- Plain comma-separated, no spaces, newline-terminated lines. Only if a value contains a comma or quote, wrap it in double quotes.
- If there are no surviving requests, the file is just the header line.
## Step 5: Write course-fill.json (beside input.json)
A JSON array with one object per entry of `courses`, in the same order as in input.json (NOT sorted), each with exactly the keys `course`, `enrolled`, `waitlisted`, with integer values: `{"course": "HIS210", "enrolled": 2, "waitlisted": 1}`. Courses nobody requested get 0 and 0. `limit` rows count in neither number.
## Final check before finishing
- Row count of the CSV (excluding header) equals the number of distinct (student, course) pairs.
- No course has more `enrolled` rows than its cap; no student has more `enrolled` rows than maxCourses.
- Each course's waitlisted places run 1, 2, 3... in row order.
- For each course, enrolled + waitlisted in course-fill.json matches the CSV rows.
- Re-verify the sort of any ties by year and time, since these are the commonest errors.
## Worked example
maxCourses 2. A year-3 student asking at 10:40 is handled before a year-1 student asking at 09:00. A student waitlisted on HIS210 who then gets places on two other courses still gets both, because a waiting-list place does not count toward the limit; but a student already holding two enrolled places who asks for a full course is `limit`, not waitlisted.