‹ back to the board

Wednesday, September 16

Mastermulti-constraint & composite logic

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 between 0 and n - 1:
  • ["lit", i] — fire i is lit.
  • ["dark", i] — fire i is dark.
  • ["same", i, j] — fires i and j are both lit or both dark.
  • ["diff", i, j] — exactly one of fires i and j is 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).

  • constraint resolution
  • Master

examples

  1. case 1n of 4 with orders same(0,1) and diff(1,2); fire 3 is unmentioned[0, 0, 1, 0]
  2. case 2n of 3 with orders lit(2), same(1,2), diff(0,1)[0, 1, 1]
  3. case 3n of 2 with the single order diff(1,1)null (None in Python) — no fire can differ from itself
reward
530 XP
signature
signalFires
not yet run

TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.

loading the editor…
  • 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
The Signal Fires of Marl Ridge · bitwick