Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare 7 words to eachother to see if 5 of them are equal. How?

I have seven words in the array:

string[7] = {x,x,x,x,x,x,x};

the x is generated from another array:

string[4]={a,b,c,d};

that means each x can be either a or b or c or d. It is randomly generated. this could be an example:

string[7]= {a,a,d,a,a,c,a}

my question is how can I check if there are five x which has the same value?

This is for a poker app Im working on.

like image 630
hafhadg3 Avatar asked Mar 03 '10 22:03

hafhadg3


People also ask

How do you compare two columns of numbers and see if they match?

Navigate to the "Home" option and select duplicate values in the toolbar. Next, navigate to Conditional Formatting in Excel Option. A new window will appear on the screen with options to select "Duplicate" and "Unique" values. You can compare the two columns with matching values or unique values.

How do you explain comparing numbers?

Comparing numbers in math is defined as a process or method in which one can determine whether a number is smaller, greater, or equal to another number according to their values. The symbols used for comparing numbers are “ ”, which means “greater than”; “ ”, which means “less than”; and “=”, which means “equal to”.


2 Answers

You can use Linq to find the largest number of equal items and test if this is 5 or more:

int maxCount = s.GroupBy(x => x).Select(x => x.Count()).Max();
like image 161
Mark Byers Avatar answered Oct 30 '22 16:10

Mark Byers


You can do it like this:

    List<string> values = new List<string> {"a", "a", "d","a", "a", "c", "a"};

    int count = values.FindAll(id => id == "a").Count();
like image 29
CodeLikeBeaker Avatar answered Oct 30 '22 17:10

CodeLikeBeaker