65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIconstarIcon

5.00/5 (3 votes)

Jul 21, 2016

CPOL
viewsIcon

14286

downloadIcon

33

Scoring the FOSW of the day for people who find it difficult

Introduction

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);

History

  • 2016-07-21: Original version