Oh no! Nemo, our small clown fish is lost in this ASCII ocean and his dad Marlin is trying to find him.
Your task is to get Marlin to Nemo safely. But beware, we have a feeding frenzy Bruce on the loose, so better avoid him at all costs!
Details
You are given a rectangular ASCII ocean grid containing only lowercase alphabets a-z
. This ocean will have nemo
, marlin
and bruce
inside it in the form of a continuous polyomino, always starting from the top most cell in the first column of polyomino. So for example, out of all possible tetrominos, the valid ones are listed in the below snippet
nemo
n
e
m
o
no
em
ne
om
nem
o
o
nem
n
e
mo
o
m
ne
ne
m
o
n
emo
ne
mo
n
em
o
mo
ne
But forms like these are invalid and won't be present in the input:
omen
ne
mo
nem
o
o
m
en
nem
o
n
eo
m
Finally, your task is to find a path from the marlin
polyomino tile to the nemo
polyomino tile making sure that any cell in your path is not adjacent to the bruce
polyomino tile. Your output should replace all alphabets which are not part of the marlin
tile, nemo
tile and the path connecting them both with a character from the printable ASCII range (including space) other than the lowercase a-z
.
Example
If the input ocean is as following:
oxknvvolacycxg
xmliuzsxpdzkpw
warukpyhcldlgu
tucpzymenmoyhk
qnvtbsalyfrlyn
cicjrucejhiaeb
bzqfnfwqtrzqbp
ywvjanjdtzcoyh
xsjeyemojwtyhi
mcefvugvqabqtt
oihfadeihvzakk
pjuicqduvnwscv
(with the 3 polyominos being:
...n..........
.mli..........
.ar...........
..............
....b.........
....ruce......
..............
.....n........
.....emo......
..............
..............
..............
)
Then a valid solution may look like:
...n..........
.mli..........
.ar...........
.u............
.n............
.i............
.z............
.wvjan........
.....emo......
..............
..............
..............
Below snippet contains a few more examples:
oxknvvolacycxg
xmliuzsxpdzkpw
warukpyhcldlgu
tucpzymenmoyhk
qnvthsalyfrlyn
cibrucejhiaebu
bzqfnfwqtrzqbp
ywvjanjdtzcoyh
xsjeyemojwtyhi
mcefvugvqabqtt
oihfadeihvzakk
pjuicqduvnwscv
...n..........
.mli..........
.ar...........
.u............
qn............
c.............
b.............
ywvjan........
.....emo......
..............
..............
..............
----------------------------------------------
nemokjahskj
sdjsklakdjs
uqiceasdjnn
sbruakmarli
nemokjahskj
..........s
..........n
......marli
----------------------------------------------
Notes
- The grid will always be a perfect rectangle and will contain only one polyomino tile of
nemo
,marlin
andbruce
. - Your path should not go through
bruce
or any of the 4 adjacent (up, down, left and right) cells of any cell in thebruce
tile. - It is always guaranteed that there will be at least one valid path from
marlin
tonemo
. - There is no requirement of a shortest path here, so go nuts!
- Even though you don't have to find the shortest path, any cell in the path (path not including marlin or nemo) cannot be adjacent to more than two other cells in the path.
- The path should not go through the
marlin
ornemo
tiles, as it would then confuse the little fishes in choosing a direction. - As usual, you may write a program or function, taking input via STDIN (or closest equivalent), command-line argument or function parameter, and producing output via STDOUT (or closest equivalent), return value or function (out) parameter.
- If multi-line input is not possible, then you may assume that the grid is joined by the
|
character instead of\n
. You may also take the input as an array of grid rows.
This is code golf so the shortest entry in bytes wins.
k
above thel
in marlin was visible? (making the path from the n in marlin to nemo) \$\endgroup\$