The Challenge
Consider the 3x3 king grid, as shown in the following ASCII graphic:
A--B--C
|\/|\/|
|/\|/\|
D--E--F
|\/|\/|
|/\|/\|
G--H--I
You are given as input a length-9 list of integers that represent a labeling of the nodes. For example, the input [0,1,1,2,1,0,5,5,1]
represents the following labeling:
0--1--1
|\/|\/|
|/\|/\|
2--1--0
|\/|\/|
|/\|/\|
5--5--1
Your output is the set of integers in the input that form connected sets of nodes. More explicitly, the output should contain an integer n
from the input if and only if the set of nodes with label n
is connected. In this example, an acceptable output would be [1,2,5]
, since the two 0
s are not connected. The lowest byte count wins.
Detailed rules
- You can choose a fixed ordering for the nodes in your input list, and you should state this in your answer. In the order EFBDHCAGI, the above labeling would be given as
[1,0,1,2,5,1,0,5,1]
. - You can write either a full program or a function. In the latter case, the output can be a set of integers if your language supports those.
- The output list may contain duplicates, but its length must not exceed 9.
- Standard loopholes are disallowed.
Test cases
These have single-digit numbers aligned to the grid; adjust them to your chosen order.
011
210 => 1 2 5
551
010
202 => 0 2
221
110
123 => 0 2 3
221
111
111 => 1
111
111
141 => 1 4
111