The presence of a list of structures or, possibly, a list of arrays, each of which contains 3 elements, for example
12 8 7 5 1 0 7 3 2 10 6 5 6 2 1 8 4 3 6 1 5 7 2 6 8 3 7 9 4 8 11 7 6 13 9 8 11 6 10 12 7 11 13 8 12 14 9 13
I want to get rid of elements that have 2 common elements in the list, in the example I would like to remove
5 1 0 6 2 1 6 1 5 7 3 2 7 2 6 8 4 3 8 3 7 has 2 same items as row 7,3,2 9 4 8 has 2 same items as row 8,4,3 10 6 5 11 7 6 11 6 10 has 2 same items as row 11,7,6 12 7 11 has 2 same items as row 11,7,10 12 8 7 13 8 12 13 9 8 14 9 13 has 2 same items as row 13,9,8
Therefore, using the structs approach, I think that sorting the list by element A, and then looping and comparing the elements, so if the current element has 2 values ββequal to another element in the list, I do not add it to the list of results, however I am stuck and don't know if there is a better approach
struct S { public int A; public int B; public int C; } public void test() { List<S> DataItems = new List<S>(); DataItems.Add(new S { A = 1, B = 2, C=3} ); DataItems.Add(new S { A = 12, B = 8, C = 7 }); DataItems.Add(new S { A = 5, B = 1, C = 0 }); DataItems.Add(new S { A = 7, B = 3, C = 2 }); DataItems.Add(new S { A = 10, B = 6, C = 5 }); DataItems.Add(new S { A = 6, B = 2, C = 1 }); DataItems.Add(new S { A = 8, B = 4, C = 3 }); DataItems.Add(new S { A = 6, B = 1, C = 5 }); DataItems.Add(new S { A = 7, B = 2, C = 6 }); DataItems.Add(new S { A = 8, B = 3, C = 7 }); DataItems.Add(new S { A = 9, B = 4, C = 8 }); DataItems.Add(new S { A = 11, B = 7, C = 6 }); DataItems.Add(new S { A = 13, B = 9, C = 8 }); DataItems.Add(new S { A = 11, B = 6, C = 10 }); DataItems.Add(new S { A = 12, B = 7, C = 11 }); DataItems.Add(new S { A = 13, B = 8, C = 12 }); DataItems.Add(new S { A = 14, B = 9, C = 13 }); var sortedList = DataItems.OrderBy(x => xA); List<S> resultList = new List<S>(); for (int i = 0; i < sortedList.Count (); i++) { for (int j = i+1; j < sortedList.Count(); j++) { if (sortedList.ElementAt(i).A == sortedList.ElementAt(j).A || sortedList.ElementAt(i).A == sortedList.ElementAt(j).B || sortedList.ElementAt(i).A == sortedList.ElementAt(j).C) {
Is there a more efficient way to get a list without having an element with two identical elements, so I would get a solution instead of hardcoding?
5 1 0 6 2 1 6 1 5 7 3 2 7 2 6 8 4 3 10 6 5 11 7 6 12 8 7 13 8 12 13 9 8