The Sealed Decrees of the Lissadel Revel
Each midsummer the Thorn Court of Lissadel Hollow holds its Revel, and no mortal or fae may cross the ring of foxgloves without the Court's leave. The Court's heralds have pinned their decrees to the board, together with the names of those who seek entry. The Court wants a reckoner who can say, for every guest, whether the decrees admit or bar them.
Guests. Each guest is a string of three lowercase words joined by colons: folk:house:title, for example "elf:rowan:knight". A guest never contains *.
Decrees. Each decree is a string of the form verdict pattern, optionally preceded by a single !: - verdict is exactly admit or bar. - A single space separates the verdict from the pattern. - pattern is three fields joined by colons, in the same order as a guest (folk:house:title). Each field is either a lowercase word or *. - A decree that begins with ! is sealed. Any other decree is unsealed.
Examples of decrees: "admit elf:*:*", "bar *:*:knight", "!bar goblin:*:*".
A field is named if it is a word rather than *. A decree applies to a guest when every named field in its pattern is equal to the guest's field in the same position. A * field matches anything.
Choosing the ruling decree. Among the decrees that apply to a guest, one decree rules. Compare any two applicable decrees by the following tests, in order. The first test that tells them apart decides which one outranks the other: 1. A sealed decree outranks an unsealed one. 2. A decree with more named fields outranks one with fewer. 3. A decree that names the folk field outranks one that does not. 4. A decree that names the house field outranks one that does not. 5. A decree that names the title field outranks one that does not. 6. A bar decree outranks an admit decree.
The guest receives the verdict of the decree that outranks all the others. If no decree applies to a guest, that guest's verdict is bar.
Write revelVerdicts(decrees, guests): - decrees is a list of decree strings, which may be empty. - guests is a list of guest strings, which may be empty. - Return a list of strings with the same length as guests. Each entry is "admit" or "bar" and is the verdict for the guest at the same position.
All inputs are well formed.
examples
- case 1
decrees "admit elf:*:*" and "bar *:*:knight"; guest "elf:oak:knight"["admit"]: both decrees apply and each names one field, but naming the folk field outranks naming the title field - case 2
decrees "admit *:rowan:knight" and "admit elf:*:*" and "bar elf:ash:*"; guests "elf:ash:knight" and "dwarf:rowan:knight"["bar", "admit"]: for the elf, "bar elf:ash:*" names two fields and beats "admit elf:*:*"; for the dwarf, only "admit *:rowan:knight" applies - case 3
decrees "!bar goblin:*:*" and "admit goblin:moss:piper"; guest "goblin:moss:piper"["bar"]: the sealed decree outranks the unsealed one, even though the unsealed one names all three fields - case 4
decrees "admit fae:*:*" and "bar fae:*:*"; guests "fae:thorn:queen" and "human:fen:smith"["bar", "bar"]: identical patterns tie until the last test, where bar wins; no decree applies to the human, so the human is barred
- reward
- 540 XP
- signature
revelVerdicts
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- mixed court with every rule in play
- identical patterns tie and bar wins
- no guests
- no decrees bars everyone
- sealed against sealed falls back to specificity
- house outranks title at one named field
- two named fields decided by position
- vague sealed decree beats exact unsealed
- count beats folk position