How can I check if 3 out of 5 integer are the same

c#, integer

Solution

first put them all in a single collection, rather than having separate variables:

var numbers = new[]{a,b,c,d,f};

Then group them, find the count of each group, and see if anything meets your criteria.

var isLargeGroup = numbers.GroupBy(n => n, (key, group) => group.Count() )
    .Any(count => count >= 3);

Problem

Let's say I have 5 integers. ``` int a = 1; int b = 2; int c = 5; int d = 1; int f = 1; ``` I want to check if any of these 3 out of 5 integers are the same. I've tried some stuff however it got very long (500+ lines) and thought this wasn't a good method to use.

Original source