Go Pro!

My Secret Number

My Secret Number is a mathematical puzzle hosted at The Problem Site. The following is a description of the design process for this game. This is interesting both from a mathematical standpoint and a programming standpoint. If you have not played the game, you may wish to click here to play.

Preliminary Work

Most of the design work was done (back in the dark ages!) using Visual Basic, connected to an Access database, using the ADO (Active Data Objects) data access components. The database structure includes a record for each puzzle. The database fields contain the puzzle solution and the 'rules' which define the solution.

Contrary to the 'intuitive' approach, the database was not populated by randomly selecting solutions and creating rules that fit the solution. Instead, the rules were randomly generated according to the following process: Each rule is made of three components: the rule's 'subject', the 'comparison', and the 'value'. You can think of these as the 'subject', 'verb', and 'object' of the rule. Each rule was created by randomly selecting one of each component. For example, the randomly selected 'subject' might be 'The product of the first two digits'. The random 'verb' might be 'is less than', and the random 'object' might be '25'. Thus the rule would be 'The product of the first two digits is less than 25.'

Once a rule is created, the Visual Basic Application essentially 'crosses out' (eliminates) every three digit number that does not meet the criteria of the rule. The next step is to make sure that the rule didn't elimiate all the three digit numbers. If it did, the rule is discarded, and another rule is randomly created to replace it.

Now a second rule is added to the first one, according to the same process. This time, though, the VB App only needs to check the numbers that passed the first rule. Once again, if all the values were eliminated, the rule is discarded.

Populating The Database

Eventually, the rules will narrow down the choices to just a single number. This number is the 'solution'. The solution, and the randomly selected rules, are added to the database. To conserve space, the rules are encoded using digits to represent the values of the 'subject', 'verb', and 'object'.

I expected this random process to take a long time. In fact, it took only a few minutes for the application to generate over a thousand different puzzles. Of course, this means that there are many puzzles which have the same solution, but each one is unique, because of the different rules used to define the solution.

I ran the program long enough to fill the database with over 6000 different puzzles. Some have only two rules, like the one listed below:

The difference of my first two digits is 9.
The difference of my last two digits is 9.

Other puzzles have up to 10 different rules. Of course, in these cases, not all the rules 'do' very much. For example, if one rule says 'The sum of the digits is 5', a rule that says 'The product of the digits is less than 50' does not eliminate any choices. It becomes the job of the problem solver to determine which rules are 'useful'.

Putting It Together

When you begin a game online, the server randomly selects a record from the database, reads the solution, and decodes the rules. The rule text is displayed, and the user is left to determine the solution.

In addition, there are two fields in the database which allow the server to track the number of correct and incorrect solutions for each puzzle. Thus, after each puzzle has been played many many times, I can use this information to sort the puzzles into 'easy', 'difficult', and 'challenging'. 

Blogs on This Site

Reviews and book lists - books we love!
The site administrator fields questions from visitors.
Like us on Facebook to get updates about new resources
Pro Membership