‹ back to the board

Friday, September 4

Mastermulti-constraint & composite logic

The Runaway Ore Cart

The mine under bitwick is worked out, but one cart still sits on the rails, and the mine-captain will pay for a single last run.

You are given rows, a non-empty list of strings of equal length: the mine floor seen from above. Row 0 is the north edge and column 0 the west edge, so north is row minus one, south is row plus one, east is column plus one, west is column minus one. Exactly one square holds S. The floor is at most 12 by 12 and holds at most 6 switch squares.

The squares:

  • . bare rail, and S behaves as bare rail
  • * a pile of ore
  • / and \ mirrors
  • # a buffer
  • T a switch

The cart starts on the S square heading east. It then repeats this step: look at the square one place ahead in its current heading.

  • If that square is outside the grid, the run ends.
  • If it holds #, the cart does not move, and its heading reverses (turns 180°).
  • Otherwise the cart moves onto that square, and the square acts on it:
  • . or S: nothing.
  • *: one ore is taken, and that square becomes bare rail for the rest of the run. The heading does not change.
  • /: east becomes north, north becomes east, west becomes south, south becomes west.
  • \: east becomes south, south becomes east, west becomes north, north becomes west.
  • T: every switch square keeps its own tally. On the cart's first arrival at that square the cart turns 90° left (east→north, north→west, west→south, south→east); on its second arrival at that same square, 90° right; alternating on every later arrival there.

oreRun(rows) returns the number of ore taken if the run ends, and -1 if the cart never leaves the grid.

  • simulation with multiple constraints
  • Master

examples

  1. case 1rows = ["S.*.*"]2 - the cart rolls east along the single row, takes both piles, and leaves past the last column
  2. case 2rows = ["#S*#"]-1 - it takes the one pile, then bounces between the two buffers forever; the ore already taken does not matter
  3. case 3rows = ["/\..", "ST*.", "\/.."]1 - the switch turns the cart left, the four mirrors bring it back to the same switch, which now turns it right, and it leaves east past the ore
reward
520 XP
signature
oreRun
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…
  • straight run takes both piles
  • mirrors bend the rails
  • switch turns left then right
  • trapped between two buffers
  • ore taken but never leaves
  • each switch keeps its own tally
  • same corridor twice is not a loop
The Runaway Ore Cart · bitwick