This is the second in a series of Island Golf challenges. Previous challenge
Two hermits have arrived on a desert island. Since they came seeking solitude, they wish to live as far away from each other as possible. Where should they build their huts to maximize the walking distance between them?
Input
Your input will be a rectangular grid consisting of two characters, representing land and water. In the examples below, land is #
and water is .
, but you may substitute any two distinct characters you wish.
...........
...##......
..#####....
..#######..
.#########.
...#######.
...#####.#.
....####...
...........
There will always be at least two land tiles. The land tiles will all be contiguous (i.e. there's only one island). The water tiles will also be contiguous (i.e. there are no lakes). The outer border of the grid will all be water tiles. Land tiles will not be connected diagonally: i.e., you will never see something like
....
.#..
..#.
....
Output
Your code must output the same grid, with two hut locations marked on it. In the examples below, the hut locations are marked with X, but you may substitute any character as long as it is distinct from your land and water characters.
The hut locations must be two land tiles, chosen so as to maximize the walking distance between them. We define walking distance as the length of the shortest path, entirely on land, between the two points. Land tiles are considered adjacent horizontally or vertically, but not diagonally.
A possible solution for the above island:
...........
...X#......
..#####....
..#######..
.#########.
...#######.
...#####.X.
....####...
...........
The walking distance between these two points is 11, which is the greatest distance between any two points on this island. There is another distance-11 solution:
...........
...##......
..X####....
..#######..
.#########.
...#######.
...#####.X.
....####...
...........
Details
Your solution may be a full program or a function. Any of the default input and output methods are acceptable.
Your input and output may be a multiline string, a list of strings, or a 2D array/nested list of characters/single-character strings. Your output may (optionally) have a single trailing newline. As mentioned above, you may use any three distinct characters in place of #.X
(please specify in your submission which characters you're using).
Test cases
A. Islands with unique hut placements:
....
.##.
....
....
.XX.
....
......
......
..##..
...#..
......
......
......
......
..X#..
...X..
......
......
........
.#####..
.##..##.
.#..###.
.##..##.
........
........
.#####..
.##..##.
.#..###.
.#X..#X.
........
.........
.#####.#.
.#...#.#.
.#.###.#.
.#.....#.
.#######.
.........
.........
.#####.X.
.#...#.#.
.#.X##.#.
.#.....#.
.#######.
.........
......
..###.
.###..
...#..
......
......
..##X.
.X##..
...#..
......
B. Example of an island with multiple possible solutions:
........
....##..
...####.
..###...
.#####..
.#####..
..##....
........
Possible outputs:
........
....#X..
...####.
..###...
.#####..
.X####..
..##....
........
........
....#X..
...####.
..###...
.#####..
.#####..
..X#....
........
........
....##..
...###X.
..###...
.#####..
.X####..
..##....
........
........
....##..
...###X.
..###...
.#####..
.#####..
..X#....
........
This is code-golf: the shortest code in each language wins.
...... ..###. .###.. ...#.. ......
(breaks programs that only BFS twice) \$\endgroup\$