Skip to main content
1 of 2
Kevin Cruijssen
  • 136.2k
  • 14
  • 155
  • 394

05AB1E, 85 bytes

2FINi(}Θ©˜!ƶIgä®*Δ2Fø0δ.ø}2Fø€ü3}®*εεÅsyøÅs«à]+ÐU˜ê©¦vyX®¦y†AS:¾1:'a0:4FJTx:€Søí}S2¢: 

"If you have participated in the previous challenge, having to count the liberties of multiple groups may require a quite different strategy." That's an understatement, haha. This answer is almost 8 times as large as my 05AB1E answer for the related challenge. Although this is primarily because flood-filling is so expensive in 05AB1E; and the conversion I use is currently pretty verbose as well..

Uses -1/1 for O/X and 0 for empty spaces.

Try it online or verify all test cases.

Explanation:

TODO: Will add an explanation later today. I'm first going to lunch and have a meeting at work.

As a short summary for now:

  1. Flood-fill the individual islands, which I've done in 05AB1E before for this challenge (which actually contained a bug that I discovered thanks to the final test case here);
  2. Loop over the islands:
    1. Convert the matrix to something usable, so a similar approach can be used as in the linked challenge (converts 0s to 1s; the current island to 0s; and the other islands to lowercase letters).
    2. Actually use that approach to calculate the counts of each island
    3. Replace the islands with these counts.
Kevin Cruijssen
  • 136.2k
  • 14
  • 155
  • 394