# Excluding Numbers from the List of List of in[]

Page 1 of 1

## 4 Replies - 551 Views - Last Post: 14 November 2012 - 06:06 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=300184&amp;s=c6878a6d364f72b41419c9df4f5c6b12&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 DeerPark

• New D.I.C Head

Reputation: 0
• Posts: 4
• Joined: 11-November 12

# Excluding Numbers from the List of List of in[]

Posted 14 November 2012 - 09:23 AM

So, I have a list of list of integers, say it has only two sub list for now.

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 sublist 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.
```            List<int> listOf1To10 = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
List<int> listOf11To20 = new List<int>() { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
List<int> listOf21To30 = new List<int>() { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
List<int> listOf31To40 = new List<int>() { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 };
List<int> listOf41To45 = new List<int>() { 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.

}

```

Is This A Good Question/Topic? 0

## Replies To: Excluding Numbers from the List of List of in[]

### #2 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 4684
• Posts: 8,273
• Joined: 08-June 10

## Re: Excluding Numbers from the List of List of in[]

Posted 14 November 2012 - 09:33 AM

I've read and re-read your post and I have no idea what it is you're actually trying to do. Can you break your logic down to be more step-by-step and simple? That'll help us help you, and it will also help you.

### #3 tlhIn`toq

• Left site for a while

Reputation: 5927
• Posts: 12,924
• Joined: 02-June 10

## Re: Excluding Numbers from the List of List of in[]

Posted 14 November 2012 - 09:42 AM

Quote

So, I have a list of list of integers,
List<int[]> result1 =

No. You have a list of integer array List<int[]>. Not a list of List of integers. List<List<int>>

Then you are coding for something entirely different than what you set up.

01 List<int> listOf1To10

This is a list of integers. Not a list of integer ARRAY as you describe in the question.

Not only are we confused about what you are doing - but I think you have confused yourself about how you are doing it.

I'd suggest you start on a whiteboard and plan a lot more of the logic before you start typing.

This post has been edited by tlhIn`toq: 14 November 2012 - 09:43 AM

### #4 DeerPark

• New D.I.C Head

Reputation: 0
• Posts: 4
• Joined: 11-November 12

## Re: Excluding Numbers from the List of List of in[]

Posted 14 November 2012 - 09:58 AM

Curtis Rutland, on 14 November 2012 - 09:33 AM, said:

I've read and re-read your post and I have no idea what it is you're actually trying to do. Can you break your logic down to be more step-by-step and simple? That'll help us help you, and it will also help you.

Thank you for your response.
I apologize for making it unclear. As a matter of fact like "tlhIn`toq" has mentioned I have confused myself on list of integer array.

So What I am trying to achieve is - Let's say the input of the users are 6 digit number separated by comma. There will be a list of those numbers which I am currently assigning to integer array ( which is result1 from my code).

So now, the goal is to check if those input number belongs to at least 4 groups. So if one of the user input number was
4, 15, 6, 7,8,30 then this should be removed from the final arraylist since this does not meet the condition of having the numbers coming from atleast 4 groups.

Thanks for pointing that out. I got totally lost while working on this logic.

### #5 Momerath

• D.I.C Lover

Reputation: 1016
• Posts: 2,457
• Joined: 04-October 09

## Re: Excluding Numbers from the List of List of in[]

Posted 14 November 2012 - 06:06 PM

Set a counter to zero.
For each intersect, if the count of elements is greater than zero, add 1 to the counter.
If the counter is 4 or more, then you have four or more groups.