Revision 5f9eb7cc-c5bb-4ab7-aedd-dbc746fe9e42 - Code Golf Stack Exchange

## Introduction
For the purposes of this challenge, we will define the *neighbours* of an element \$E\$ in a square matrix \$A\$ (such that \$E=A_{i,j}\$) as all the entries of \$A\$ that are immediately adjacent diagonally, horizontally or vertically to \$E\$ (i.e. they *"surround"* \$E\,ドル without wrapping around).

For pedants, a formal definition of the neighbours of \$A_{i,\:j}\$ for an \$n\times n\$ matix \$A\$ is (0-indexed):
$$N_{i,\:j}=\{A_{a,\:b}\mid(a,b)\in E_{i,\:j}\:\cap\:([0,\:n)\:\cap\:\Bbb{Z})^2\}$$
where
$$E_{i,\:j}=\{i-1,\:i,\:i+1\}\times \{j-1,\:j,\:j+1\} \text{ \\ } \{i,\:j\}$$

Let's say that the element at index \$i,\:j\$ lives in hostility if it is coprime to *all* its neighbours (that is, \$\gcd(A_{i,\:j},\:n)=1\:\forall\:n\in N_{i,\:j}\$). Sadly, this poor entry can't borrow even a cup of sugar from its rude nearby residents...

## Task

Enough stories: Given a square matrix \$M\$ of positive integers, output one of the following:

- A flat list of elements (deduplicated or not) indicating all entries that occupy some indices \$i,j\$ in \$M\$ such that the neighbours \$N_{i,\:j}\$ are hostile.
- A boolean matrix with \1ドル\$s at positions where the neighbours are hostile and \0ドル\$ otherwise (you can choose any other consistent values in place of \0ドル\$ and \1ドル\$).
- The list of pairs of indices \$i,\:j\$ that represent hostile neighbourhoods.

[Reference Implementation in Physica](https://tio.run/##fZLfbtMwGMWvm6c4RDC1moqSdB0oplMr0FAnQBNI3GS5aINhblNnyh8BSi3tclzzCogH64uUL7bXpYwhJXIcn@@czz/76vJ7IZLZdntayQTvuPhyOc@qvIgmIVJRlAwihJA0LvQYIzQLodOROzVGqJXTOc1y5NlXbG5uUIu@T8X0HPqKxJ3pZzzqetj8@KU1L/CGy/Gk9lQvRJLJUsiKk6zxSLK0Wkljs2hsFvRYm7aP1WkrjKHNsF6jSwHMrvYwGqFLfSz2c9rdH1L7k5qKVG2KFG3mPS@rXOJO5jiOhvT65atoZqHM76DQSP3RIsHwDYul3kIUYHP9G2@FjOoZlag4tjxmeEIa6m9@@@HpLRqT5a4HmlP4albm4hstTOVVVT52pvKTSLhl30YfeTqQoESmJu77TeRfaB@SdXjKV1yWZGz@75FxOvvn3royRs3Qoh@TPMmucrHipJ2kadTtn2AZaog2h2EZN3v3exiPW7yb2vOcsEYtQwZ3c/3TZdgVu/0Tmn4o86hV@jRdVEUZDYYxCdZuU62biA14OzP3yWJsLsHexVGOY@LdC3khz7OiEPOUI6tKwl@Ebny7/JHnhcgk/JCC6n8wgz0d1sZvc9U9m0Db1N0pw1mvLcXBAfzmfnva8OyBU0Qffmwyp/@V3EseNMk2LN5u6/r4iMH36D1S1FLwjCEIGAZBMxsOGIbPaXas1B8 "Physica – Try It Online") – supports [Python](https://tio.run/##fZLfbtMwFMavm6f4iGBKtRbVrbZBQqdWoKFOgCaQuPF80QbD3KZOlT8ClEba5bjmFRAP1hcpJ47XpYwhRXKc853vO/7Fq6vvqQqn2@1ZrkO8k@rL1SzOk5SPfUQqzQIoH0rTOjergF8XfKeld2oMUZRO6yxOkMRfsbm5QaG6jJrpOWQliVuTz3jk9bD58ctoXuCN1KNx0SvbPsJYZ0rnkmSVRxhH@VLXNvPKZk6PtWn6WJ2xwgjGDOs1PAoIbLWN4RAezTHfz2lOf0jjjwtqKou6qaTDvJdZnmjcyRzHMZBev3zFpxbK7A4KrTQfFQkGq1kszBF4H5vr33irNC@m1FIKYXlM8YQ0NN/s9qVnjlibLHYz0J7Cl9MsUd@oMNGrPHvsTPQnFUrLvome90wgQeF1j@iyKvIvtA/JWjKSS6kzMq6/75FxWvv/vXFlanWABn1B8jBeJWopSTuOIu51T7HwDUSbE2AhqrOzNkajBu@q9yIhrLxhGMDdXP90A@ya3e4pbT9kCW@0Po3meZrxwZEgwdqtus0QogZvd/V9shirS7B3cUrHWZl491Jf6os4TdUskojzjPCnvituyx9lkqpYg/kUVPyDGezfCZr4bW55z6ZvbApvEuC83ZTi4ACsut89Y3j@wF9EF0zUmZP/Su4lD6pkGya2W84Hzzo4OemAMdEBZ/R2xDoY9Kvd8THVqM6eC/EH) syntax as well for I/O. You can take input and provide output through any [standard method](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) and in any reasonable format, while taking note that [these loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden by default. This is code-golf, so the shortest code in bytes (in every language) wins!

## Example

Consider the following matrix:

$$\left(\begin{matrix}
64 & 10 & 14 \\
27 & 22 & 32 \\
53 & 58 & 36 \\
\end{matrix}\right)$$

The corresponding neighbours of each element are:

 i j – E -> Neighbours | All coprime to E?
 |
 0 0 – 64 -> {10; 27; 22} | False
 0 1 – 10 -> {64; 14; 27; 22; 32} | False
 0 2 – 14 -> {10; 22; 32} | False
 1 0 – 27 -> {64; 10; 22; 53; 58} | True
 1 1 – 22 -> {64; 10; 14; 27; 32; 53; 58; 36} | False
 1 2 – 32 -> {10; 14; 22; 58; 36} | False
 2 0 – 53 -> {27; 22; 58} | True
 2 1 – 58 -> {27; 22; 32; 53; 36} | False
 2 2 – 36 -> {22; 32; 58} | False

And thus the output must be one of the following:

 - `{27; 53}`
 - `{{0; 0; 0}; {1; 0; 0}; {1; 0; 0}}`
 - `{(1; 0); (2; 0)}`

## Test cases

 Input –> Version 1 | Version 2 | Version 3

 [[36, 94], [24, 69]] ->
 []
 [[0, 0], [0, 0]]
 []
 [[38, 77, 11], [17, 51, 32], [66, 78, 19]] –>
 [38, 19]
 [[1, 0, 0], [0, 0, 0], [0, 0, 1]]
 [(0, 0), (2, 2)]
 [[64, 10, 14], [27, 22, 32], [53, 58, 36]] ->
 [27, 53]
 [[0, 0, 0], [1, 0, 0], [1, 0, 0]]
 [(1, 0), (2, 0)]
 [[35, 85, 30, 71], [10, 54, 55, 73], [80, 78, 47, 2], [33, 68, 62, 29]] ->
 [71, 73, 47, 29]
 [[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]
 [(0, 3), (1, 3), (2, 2), (3, 3)]



AltStyle によって変換されたページ (->オリジナル) /