Toy data
board =
{{1, 1, 0, 4, 0, 0, 9, 9, 9, 9},
{0, 0, 0, 4, 0, 0, 0, 0, 0, 0},
{5, 0, 0, 4, 0, 7, 7, 7, 0, 8},
{5, 0, 0, 0, 0, 0, 0, 0, 0, 8},
{5, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{5, 0, 0, 0, 4, 0, 0, 0, 0, 6},
{0, 0, 0, 0, 4, 0, 0, 0, 0, 6},
{3, 3, 0, 0, 0, 0, 0, 0, 0, 6},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 3, 3, 3, 3, 3}};
Visualization
ArrayPlot[board,
ColorFunction -> "AtlanticColors",
Frame -> True,
FrameTicks -> {{All, None}, {None, Transpose[{Range @ 10, CharacterRange["A", "J"]}]}},
Mesh -> True]
is a guessing game for two players. It is played on paper grids on which each player's fleet of warships are marked. Players shoot at the other player's ships, and the objective of the game is to destroy the opposing player's fleet.
Here we don't want to guess and destroy, but find the ship locations in an elegant mathematical way. In my own coding experiments I got caught up in something that was far too complicated.
Expected result
The sorted result should look like:
result =
{"A1:B1", "A3:A6", "A8:B8", "D1:D3", "E6:E7", "F10:J10", "F3:H3", "G1:J1", "J3:J4", "J6:J8"};
Addendum
There is always some water between the ships, their lengths can range from 2 to 5 square units, and diagonal placements are not allowed.
3
; is that a typo? $\endgroup$