14,695,620 members
Articles » General Programming » Algorithms & Recipes » String Matching
Tip/Trick
Posted 21 Jul 2016

10.1K views
1 bookmarked

# Scoring the FOSW of the Day for People Who Find It Difficult.

Rate me:
21 Jul 2016CPOL
Scoring the FOSW of the day for people who find it difficult

## Introduction

All this does is let you enter two `string`s, and get the Black / White counts according to the Mastermind rules:

## Using the Code

It's pretty simple - all it needs is two lines of Linq:

```char[] solution = tbAnswer.Text.ToArray();
char[] guess = tbGuess.Text.ToArray();
int black = guess.Zip(solution, (g, s) => g == s).Count(b => b);
int white = guess.Intersect(solution).Sum
(c => System.Math.Min(solution.Count(x => x == c), guess.Count(x => x == c))) - black;
tbScore.Text = string.Format("{0}B, {1}W", black, white);```

## History

• 2016-07-21: Original version

## Share

 CEO Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

 First Prev Next
 What a birlliant Article HobbyProggy21-Jul-16 2:20 HobbyProggy 21-Jul-16 2:20
 Re: What a birlliant Article OriginalGriff21-Jul-16 2:42 OriginalGriff 21-Jul-16 2:42
 Re: What a birlliant Article HobbyProggy21-Jul-16 2:52 HobbyProggy 21-Jul-16 2:52
 Done Rules for the FOSW ![^] ```if(this.signature != "") { MessageBox.Show("This is my signature: " + Environment.NewLine + signature); } else { MessageBox.Show("404-Signature not found"); }```
 Just... Kornfeld Eliyahu Peter21-Jul-16 1:47 Kornfeld Eliyahu Peter 21-Jul-16 1:47
 Re: Just... OriginalGriff21-Jul-16 2:10 OriginalGriff 21-Jul-16 2:10
 Re: Just... Kornfeld Eliyahu Peter21-Jul-16 2:13 Kornfeld Eliyahu Peter 21-Jul-16 2:13
 Last Visit: 30-Nov-20 20:30     Last Update: 30-Nov-20 20:30 Refresh 1