The Creeping Stone of Halvane Gardens
The basilisk of Halvane Gardens is dead, but its curse was not buried with it. Some of the travellers caught among the hedges have already turned to stone, and the stone is spreading to the living who stand beside them. Before anyone goes in after them, the Halvane Wardens will pay for a reckoning: how long the curse needs to finish its work, or whether some of the trapped will be spared.
You are given grid, a list of strings of equal length describing the gardens from above. Each character is one square:
'S': a figure already turned to stone.'L': a living figure.'.': empty ground.
Every hour, each living figure that is orthogonally adjacent (up, down, left or right, never diagonal) to a stone figure turns to stone. All changes within one hour happen at once, so a figure that turns during an hour does not spread the curse until the following hour. Empty ground never turns and does not carry the curse.
Write petrifyHours(grid), which returns an integer: the number of hours until no living figure remains.
- Return
0if there are no living figures to begin with. This includes an emptygrid. - Return
-1if at least one living figure will never turn to stone.
examples
- case 1
grid of ["SLL", "..L", "LLL"]6. The curse winds right, then down, then back left around the empty ground. The last figure, in the bottom-left corner, turns in hour 6. - case 2
grid of ["SL.", "...", ".LL"]-1. The figure beside the statue turns in hour 1, but the two figures in the bottom row are cut off by empty ground and are never reached. - case 3
grid of ["S..", ".S."]0. There is no living figure to turn.
- reward
- 360 XP
- signature
petrifyHours
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- curse winds around empty ground
- two statues spread together
- statues at both ends meet in the middle
- cut-off figures are spared
- no diagonal spread
- no living figures
- empty garden
- living figures with no stone
- single statue
- single column
- long row from the west with a spared figure
- long row from the east with a spared figure