‹ back to the board

Friday, October 30

Adeptalgorithms & data structures

The Gloam-Ivy of Castle Ardwenne

Castle Ardwenne has stood empty since its lords fled, and now the gloam-ivy is taking it. The Order of the Ash Lance means to burn the vines out, but it must strike before the last bare flagstone of the great hall is swallowed. The Order will pay well for an exact count of the nights it has left.

The floor plan of the hall is given as grid, a list of strings. Every string is one row, and all rows have the same length. Each character is one cell:

  • '#' is a wall. Ivy never grows on it, and ivy cannot spread through it.
  • '.' is bare floor.
  • 'V' is floor already covered by ivy at night 0.

Each night, every bare floor cell that is directly up, down, left or right of an ivy-covered cell becomes ivy-covered. Diagonal cells do not count. Cells that become covered during a night only spread further on the following night. Ivy never leaves a cell once it has covered it.

Write ivyNights(grid), which returns an integer:

  • the number of nights after which no bare floor cell remains, or
  • 0 if the grid has no bare floor cells to begin with, whether or not any ivy is present, or
  • -1 if some bare floor cell will never be covered.

The grid may be empty, with no rows at all. An empty grid has no bare floor, so the answer for it is 0.

  • graph traversal
  • Adept
  • efficiency bonus

examples

  1. case 1grid of ["V..", ".#.", "..."]4. The bottom-right cell is the last one covered, because the ivy must go around the wall in the middle.
  2. case 2grid of ["V.#.", "..#."]-1. The column on the right is cut off by walls, so the ivy never reaches it.
  3. case 3grid of ["###"]0. There is no bare floor, so no nights are needed, even though no ivy is present.
reward
360 XP
signature
ivyNights
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…
  • wall_in_the_middle
  • walled_off_column
  • no_bare_floor
  • only_walls_no_ivy
  • floor_without_ivy
  • empty_grid
  • single_ivy_cell
  • two_roots_meet
  • two_roots_winding
  • long_serpentine_hall
The Gloam-Ivy of Castle Ardwenne · bitwick