The Signal Fires of Marl Ridge
A line of signal fires stands along Marl Ridge, numbered 0 to n - 1. Each night every fire is either lit or dark, and the warden's slate of standing orders says which fires must agree and which must not.
signalFires(n, rules) takes:
n— a non-negative integer, the number of fires.rules— a list of orders. Each order is a list whose first element is one of these four strings, followed by fire numbers, each between0andn - 1:["lit", i]— fireiis lit.["dark", i]— fireiis dark.["same", i, j]— firesiandjare both lit or both dark.["diff", i, j]— exactly one of firesiandjis lit.
In a same or diff order, i and j may be the same number. Orders may repeat and may be listed in any sequence; all of them apply at once, and none overrides another.
Return a list of n integers, 1 for a lit fire and 0 for a dark one, obeying every order. If more than one arrangement obeys every order, return the lexicographically smallest one: compare position by position starting at index 0, taking 0 as smaller than 1. If no arrangement obeys every order, return null (None in Python).
examples
- case 1
n of 4 with orders same(0,1) and diff(1,2); fire 3 is unmentioned[0, 0, 1, 0] - case 2
n of 3 with orders lit(2), same(1,2), diff(0,1)[0, 1, 1] - case 3
n of 2 with the single order diff(1,1)null (None in Python) — no fire can differ from itself
- reward
- 530 XP
- signature
signalFires
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- a quiet ridge with no orders
- a chain lit from the middle
- free groups darken their earliest fire
- an order set against itself
- the chain contradicts the pinned fires
- an empty ridge
- repeated and self-matching orders
- a long loop that closes consistently