24 June 2011

Another weekly quiz: Logic Puzzler

Starting next week (starting, in other words, tomorrow!), the PL/SQL Challenge will offer a third weekly quiz (in addition to SQL and APEX), this time with a focus on deductive logic.

Deductive logic lies at the heart of all programming endeavors. Without logic and reason, we would not have, well, just about anything you associate with "civilization" - and certainly there would be no programming. The better you are at deductive logic, the better you will be at writing software.

So we've decided to offer a weekly quiz to help you strengthen your deductive logical thinking and problem solving skills. These quizzes have nothing to do with PL/SQL or SQL, but we hope you will find them entertaining and worth a few minutes of your time. We truly believe that the faster and easier you can sort through the choices of the logic puzzler, the better equipped you will be to write and debug your code.

The weekly logic puzzle mimics the game of Mastermind, a classic game of deductive logic. Generally, you will be presented with a set of guesses and their clues, and then you must decide which of the choices are a valid deduction from that information.

How the game works


The objective of the game is to guess the sequence of numbers that are in the four-digit solution. Each guess consists of a four digit number, each of whichmust be between 1 and 7. [Note: in the "real" Mastermind game, you use colors for the guesses, but that makes it difficult for people who are color blind to play.]

Clues are given for each guess. Each "P" clue means that a digit is in the solution and it is in the right position (in "classic" Mastermind, this is a black clue). Each "N" clue means that a digit (the number is in the solution, but it is not in the right position (in "classic" Mastermind, this is a white clue). The position of the clue does not correlate with the digits. In other words, the first clue does not apply to the first digit in the guess.

You will be presented with a set of guesses and clues. From that information, you must pick the choices that either are valid deductions from this information, or a possible solution. Here is an example:

[Note: this has been updated since the original posting to fix an error...thanks, Iudith!]

# Guess Clues
1 1 2 3 4 P,N
2 1 3 6 7 N
The clues for guess 1 tells us that two digits are in the solution, but only one is in the right location. The clue for guess 2 tells us that only one of the digits is in the solution. Given these clues, any of the following four-digit sequences could be possible solutions (and there are lots more):

  • 7 5 2 4
  • 6 2 4 5
  • 2 6 5 4
Valid deductions from these two turns include:
  • 5 must be in the solution.
  • Either 6 or 7 must be in the solution, but not both.
  • 1 is not in the solution. 
Why are they valid? Hey, why should I do all the work around here? I encourage readers to post as comments why you believe they are valid (or perhaps I made a mistake and one is not valid!). That will be a nice practice for playing the quiz.

So....I hope you find the time to play the logic puzzler. And, as with PL/SQL and SQL quizzes, you are welcome to submit your own logic puzzler for use on the site

Cheers, Steven Feuerstein