Four Wizards

A cute puzzle found on Facebook:

Puzzle. Four wizards A, B, C, and D, were given three cards each. They were told that the cards had numbers from 1 to 12 written without repeats. The wizards only knew their own three numbers and had the following exchange.

  • A: “I have number 8 on one of my cards.”
  • B: “All my numbers are prime.”
  • C: “All my numbers are composite. Moreover, they all have a common prime factor.”
  • D: “Then I know the cards of each of you.”

Given that every wizard told the truth, what cards does A have?

Share:Facebooktwitterredditpinterestlinkedinmail

11 Comments

  1. Blaine:

    Without giving the answer away, if you type the numbers in ascending order separated by commas (e.g. “a,b,c”) the MD5 hash is: dc2e3f737c555711b84147b112ed4364

  2. Blaine:

    Hint 1: B has 5 possible numbers. But if A had any of them, D couldn’t know which were held by A and which were held by B. What does this tell you about how many primes are held by D?

    Hint 2: 1 is neither prime nor composite. If D has 1, can he deduce the numbers of A and C. So who has 1?

    Hint 3: C could have {6,9,12} or three cards from {4,6,10,12}. D is able to conclusively eliminate one of these cases. That wouldn’t happen if D had 4 or 10. Would that happen if D had 9? Remember C could have any 3 of the 4 numbers in {4,6,10,12}. So what numbers remain as possible ones held by D? And what does that tell you about 9?

    Hint 4: Does the question ask you for the specific cards of B,C or D? Do you need to know them?

  3. Jonathan Kariv:

    I get that A has 1,8 and 9.

  4. Blazer:

    Can someone post a link with the full solution? I just don’t get it. (Please no email, it’s a 10minutemail…)

  5. Cristóbal Camarero:

    A has the cards 1, 8, and 9. They key point is to see who has the 12 card.

    Blaine, I have checked all the possibilities and none of them has that MD5 hash. Using this (plus trying adding newlines and similar):
    “`bash
    for a in $(seq 10)
    do
    for b in $(seq $a 11)
    do
    for c in $(seq $b 12)
    do
    suma=$(echo “$a,$b,$c” | md5sum)
    echo $a,$b,$c,$suma
    done
    done
    done
    “`

  6. L33tminion:

    Explanation here, linked to avoid spoilers.

    Re the comment above, echo adds a newline by default, you get the expected hash with `echo -n “$a,b,$c” | md5sum`.

  7. L33tminion:

    That link didn’t seem to come out correctly, should be this.

  8. Blaine:

    No newlines… try this link https://www.md5hashgenerator.com/

  9. TR:

    Extension: Instead, D says “the sum of my cards is the number of a card that one of you is holding” will determine everyone’s cards.

    Likewise (but a different solution) if D said “the sum of my cards is equal to the product of someone else’s cards.”

  10. Cristóbal Camarero:

    Right, I missed the implicit newline of `echo`. Apologies for the noise.

  11. Yusuke Tsutsumi:

    Here’s another explanation of the solution if anyone is interested: https://y.tsutsumi.io/puzzles/four-wizards

Leave a comment