The Manticore-Cots of Haverleigh Ford
By order of the Hunt-Master of Haverleigh Ford
The manticore hunts in the Ruddle Hills have begun, and stung hunters are carried down to the Sickhouse at Haverleigh Ford, where the Sisters of the Ford tend them on narrow cots. Manticore venom creeps while it goes untreated, so a hunter who waits grows more urgent with every passing stretch of hours. The Hunt-Master wants a reckoning, made in advance, of which Sister will tend each hunter and at what hour.
Write triageOrder(healers, patience, patients).
Arguments - healers: an integer, at least 1. This is the number of Sisters. They are numbered 0 to healers - 1. - patience: an integer, at least 1. - patients: a list of hunters, each given as [name, arrival, severity, duration]: - name is a non-empty string of ASCII letters. No two hunters share a name. - arrival is an integer of at least 0. It is the hour the hunter reaches the Sickhouse. - severity is an integer of at least 0. - duration is an integer of at least 1. It is the number of hours that hunter's treatment takes.
The list is not necessarily in order of arrival.
Rules 1. A hunter is *waiting* from their arrival hour until their treatment begins. 2. A Sister who begins a treatment at hour t is busy until hour t + duration. She is free again at exactly that hour, and she may begin another treatment at that same hour. 3. At any hour t when at least one Sister is free and at least one hunter is waiting, treatments begin at once. Choose one waiting hunter by rule 4 and assign that hunter to the lowest-numbered free Sister. Repeat this until no Sister is free or no hunter is waiting. Hunters arriving at hour t and Sisters becoming free at hour t both count at hour t. 4. When choosing at hour t, a hunter's *urgency* is severity + floor((t - arrival) / patience). Pick the hunter with the highest urgency. If urgencies are tied, pick the earlier arrival. If those are also tied, pick the name that comes first in plain character-by-character (ASCII) ordering.
Return
Return a list containing one triple [name, healer, start] per hunter: - healer is the number of the Sister who treats that hunter. - start is the hour that hunter's treatment begins.
Order the triples by start. Within the same hour, list them in the order the hunters were chosen. If patients is empty, return an empty list.
examples
- case 1
healers 1, patience 2; Brann (arrives 0, severity 5, takes 6), Old (arrives 1, severity 1, takes 2), New (arrives 5, severity 2, takes 2)[["Brann",0,0],["Old",0,6],["New",0,8]]. At hour 6, Old has waited 5 hours, so his urgency is 1 + 2 = 3. New has waited 1 hour, so hers is 2 + 0 = 2. Old goes first, even though his severity is lower. - case 2
healers 2, patience 100; Ina (arrives 0, severity 1, takes 3), Jory (arrives 0, severity 4, takes 5), Kell (arrives 3, severity 2, takes 2), Lise (arrives 3, severity 3, takes 1)[["Jory",0,0],["Ina",1,0],["Lise",1,3],["Kell",1,4]]. Sister 1 frees at hour 3, the same hour Kell and Lise arrive, and takes Lise at once. - case 3
healers 2, patience 1; Rook (arrives 10, severity 0, takes 2), Pell (arrives 2, severity 1, takes 3), Quin (arrives 2, severity 1, takes 1)[["Pell",0,2],["Quin",1,2],["Rook",0,10]]. Pell and Quin tie on urgency and arrival, so Pell wins on name. At hour 10 both Sisters are free, so Rook goes to Sister 0. - case 4
healers 3, patience 4, no hunters[]
- reward
- 540 XP
- signature
triageOrder
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- single healer no aging
- aging overtakes higher severity
- urgency tie broken by arrival before name
- full tie broken by name
- healer freed at arrival hour
- no hunters
- unsorted input idle gap lowest healer
- two healers with aging and three-way tie
- single late hunter
- patience one strong aging