Apologies if the title does not articulate this very well but here is what I'm trying to accomplish:
I have an array of pairs that represent links between the numbers in each pair. I need to derive from this array all the unique groups that the array of pairs represent. Some examples will illustrate this best:
Given:
[0,1]
[1,2]
Result:
[0,1]
[1,2]
Given:
[0,1]
[1,2]
[0,2]
Result:
[0,1,2]
Given:
[0,1]
[1,2]
[1,3]
[2,3]
[2,4]
Result:
[0,1]
[1,2,3]
[2,4]
Just having a hard time trying to wrap my head around the logic needed to accomplish this. Any help would be greatly appreciated (and please edit this post if you think it could be worded better).
Yes, result would be: [0,1,2], [1,2,3]
– zeke Jun 02 '18 at 08:26Essentially. I have a program where users can link different components, but they only link two components at a time. I need to show which components are linked together so I'm going to add a colored square to each indicating what is linked to what. So once I have the groups I can then just cycle through colors and assign them to the groups. Some components will have multiple squares if belong to more than one group.
– zeke Jun 02 '18 at 08:31