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

10.2K 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

## About the Author

 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?

## Comments and Discussions

 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
 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
 That's the point! Frighten them off!!! Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.
 Last Visit: 31-Dec-99 19:00     Last Update: 21-Jan-21 14:00 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.