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


  1. The clues for guess 1 tells us that two digits are in the solution, for the other two digits are 3 possiblities:
    (5,6), (5,7), (6,7). Because we have only 1 clue in second guess (6,7) is not correct so we can say:

    1- 5 must be in the solution.
    2- Either 6 or 7 must be in the solution, but not both.
    3- 1 can not be in the solution otherwise we must have 2 clues in the second guess.

    Best regards,

    Hamid Talebian

  2. Hello Steven, All,

    The deductions presented are valid because of the following:

    Since 1234 contains only 2 digits of the solution, it follows that the other 2 must be among 5,6,7.
    Similarly, since 1367 contains only 1 digit of the solution, it means that 6 and 7 cannot be both in the solution, so automatically 5 should be in the solution, together with one only of 6 or 7.
    Also, from the same 1367 clue it follows that 1 as well as 3 cannot be in the solution.
    Now back to the 1234 clue, it follows also that 2 and 4 are in the solution.

    In summary, the digits of the solution are:
    2, 4, 5 and one of 6 or 7.

    Hope that my rationale is right.

    Some thoughts:
    I suppose that the valid deductions presented were based on the assumption that the 4 digits of the solution should be distinct.
    It looks like the original game also allows for duplicates, which makes things more difficult.
    Also, what about allowing all the digits from 1 to 9, not just 1 to 7 ?

    Programmers probably always tend to over-complicate life, looks to be our "mode of being" :) :)

    Thanks a lot & Hope to have fun with this new quiz !

    Best Regards,

  3. Good point, Iudith. In the assumptions for the quiz, you will see that I explicitly rule out duplicates and blanks in the solution.

    Allowing those, along with using more digits, will indeed make the puzzle that much more difficult - and then it will take more of your time and I fear fewer people will play.

    This configuration should be sufficient to exercise our logic skills, without being all-consuming.

    Have a great weekend!

  4. The link to the Mastermind Wikipedia page is wrong.
    It goes to:
    but instead should go to:

  5. Nope, still not fixed. Still the same issue.

  6. I just tried this week's quiz, clicked on Mastermind and the page came up. Please describe (actually, send me an email: steven@stevenfeuerstein.com) specifically which link you are clicking on, perhaps a screenshot and I will hopefully narrow this down.