1. Home
  2. Computing & Technology
  3. C / C++ / C#

Programming Challenge 4 - Challenge Now Completed

By David Bolton, About.com

Back in 1971, a UK company produced a 2 player code-breaking puzzle game that took the world by storm. It was called Mastermind and here's how it is played.

There are two players- the code setter and the code breaker. The code setter picks 4 pegs from 6 colors and arranges them in order. The pegs are colored red, blue, yellow, green, white and orange. Any combination including duplicates is allowed eg RBWO or RRRG etc.

The code breaker has to guess what the color and order of the pegs are. The guess is marked by the code maker who provides a red for every peg of the right color in the right place, and a white for a correct color in the wrong place. The code breaker keeps guessing until they guess correctly or hasn't guessed it in 10 guesses. In the challenge your application gets 15 guesses.

Your mission is to write an application in C, C++ or C# that will play as the code breaker. A Windows dll has been written in C that you download, and is called by your application. The dll generates a code and then scores your application's guesses. You start with a score of ten and every guess reduces the score by 1.

You can write the application as a GUI or as a console application. It must use the provided dll which you should put in the same location as the exe. The C# file mm.cs does not specify a path to the dll, just the name mm.dll, i.e. it is assumed to be in the same location as the exe.

The Results

We had five entrants, congratulations to Andre who just pipped Lucas and Thomas. In a couple of cases I had to make very slight tweaks to compile and run the code. For the C# entries this included adding the path to where the mm.dll was located. Just alter that to your own location.

Well done to everyone who entered- There was a fair amount of code in that challenge!

More Programming Challenges

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. Projects
  5. Programming Challenges
  6. Programming Challenge 4 - Solve Mastermind codes>

©2009 About.com, a part of The New York Times Company.

All rights reserved.