Deer Park

Deer Park

  • NA
  • 39
  • 0

Excluding Numbers from the list of integer array

Nov 14 2012 10:51 AM
So, I have a list of integer array.


List<int[]> result1 = new List<int[]> { new int[] { 1, 2, 3,12,22,30 }, new int[] { 4, 15, 6, 7,8,30 } };


The elements in the integer array are always of size 6. i.e size of - { 1, 2, 3,12,22,30 }


Next I have a group.


group 1 - Numbers between 1 to 10
group 2 - Numbers between 11 to 20
group 3 - Numbers between 21 to 30
group 4 - Numbers between 31 to 40
group 5 - Numbers between 41 to 50




What I have to check and exclude from this list is - 


The integer array should at least contain number from 4 different groups. So the array of number can spread across all five groups, but should at least be in 4 groups. 


So, from the above example, { 4, 15, 6, 7,8,30 } should be excluded from the final result since the elements are coming only from 3 groups. ( 4,6,7,8 - from group1 , 15- from group2 and 30 from group3).


I am trying to achive this using following logic but I am stuck at this point. 


            int[]  listOf1To10 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[] listOf11To20 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
           int[]  listOf21To30 =  { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
            int[]  listOf31To40 = { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
            int[]  listOf41To45 =  { 41,42,43,44,45,46,47,48,49,50 };


foreach (var result1 in result)
            {


                var c = resultArrayList.Intersect(listOf1To10);
                var d = resultArrayList.Intersect(listOf11To20);
                var e = resultArrayList.Intersect(listOf21To30);
                var f = resultArrayList.Intersect(listOf31To40);
                var g = resultArrayList.Intersect(listOf41To45);
List<int> countArray = new List<int>() { listBetween1to10.Count(), d.Count(), e.Count(), f.Count(), g.Count() };


..///Stuck at this point struggling for logic to remove the elements.




}



Answers (2)