I have shapes of different colour.
Shape pink = new Shape() { name = "Pink" };
Shape yellow = new Shape() { name = "Yellow" };
Shape red = new Shape() { name = "Red" };
Shape white = new Shape() { name = "White" };
Shape blue = new Shape() { name = "Blue" };
Each shape returns a List of any other shapes it's touching, which is stored in a List.
List<List<Shape>> lists;
So lists could look like this
lists = new List<List<Shape>>()
{
new List<Shape>() { pink, yellow },
new List<Shape>() { yellow, pink, red },
new List<Shape>() { red, yellow},
new List<Shape>() { white, blue},
new List<Shape>() { blue, white}
};
which I'd like to condense and have finish up as a new List of touching shape Lists.
List<List<Shape>> result
In this instance result contains just two
List<Shape>
for example
{{pink, yellow, red}, { white, blue}}
Where the child lists share some common denominator.
I've not been able to get this working with loops, and I'm not that familiar with Linq.
Another scenario would be
lists = new List<List<Shape>>()
{
new List<Shape>() { pink, yellow },
new List<Shape>() { yellow, pink, red },
new List<Shape>() { red, yellow, blue},
new List<Shape>() { white, blue,},
new List<Shape>() { blue, white, red}
};
And result List should only contain one List
{{pink, yellow, red, blue, white}}
because all previous Lists have some relative colours.
[pink,blue]to?