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