Click here to Skip to main content
15,311,104 members
Articles / Programming Languages / C#
Posted 21 Jul 2016

Tagged as


1 bookmarked

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
21 Jul 2016CPOL
Scoring the FOSW of the day for people who find it difficult


All this does is let you enter two strings, 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);


  • 2016-07-21: Original version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wales 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

PraiseWhat a birlliant Article Pin
HobbyProggy21-Jul-16 1:20
professionalHobbyProggy21-Jul-16 1:20 
GeneralRe: What a birlliant Article Pin
OriginalGriff21-Jul-16 1:42
mveOriginalGriff21-Jul-16 1:42 
GeneralRe: What a birlliant Article Pin
HobbyProggy21-Jul-16 1:52
professionalHobbyProggy21-Jul-16 1:52 
PraiseJust... Pin
Kornfeld Eliyahu Peter21-Jul-16 0:47
professionalKornfeld Eliyahu Peter21-Jul-16 0:47 
GeneralRe: Just... Pin
OriginalGriff21-Jul-16 1:10
mveOriginalGriff21-Jul-16 1:10 
GeneralRe: Just... Pin
Kornfeld Eliyahu Peter21-Jul-16 1:13
professionalKornfeld Eliyahu Peter21-Jul-16 1:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

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