Carter Temm

Logic Puzzles

Last updated:

This is a list of logic puzzles that can be used to test and improve deductive reasoning skills.

Often called brain teasers, they are widely believed to support and enhance cognitive function through memory, concentration, creativity, and resourcefulness. I can't speak to the validity of that, but they can be fun to try and figure out among a group of friends. Some of the answers seem pretty obvious in hindsight. Others might take a while to understand even when you know them.

One note, these are not riddles. They differ from riddles in that riddles typically rely on misleading statements. These puzzles don't rely on misleading statements but on logical relationships. Each contains clues, which you can use to come up with hypotheses. Those hypotheses can then be tested and discarded through elimination. The strategic application of logic, combined with ingenuity, is key to coming up with a solution.

Sourcing

I will try to cite the source where known.

Many of these puzzles show up in technical and consulting job interviews, where they are used to evaluate how candidates think through unfamiliar problems under pressure. The goal is usually less about getting the right answer and more about demonstrating a structured, methodical approach to finding solutions.

I will continue adding to this list as time permits.

Puzzles

The Birthday Paradox

Source: Originally published by mathematician Richard von Mises in 1939.

This one should be familiar to anyone that has taken cryptography or stats 101, but it's still fun to solve.

How many people do you need in a room to have a better than 50% chance that at least two people share the same birthday?

Show Hint

Don't try to calculate the probability that two people share a birthday directly. Instead, calculate the probability that no two people share a birthday.

For each new person who enters the room, we are trying to find the odds that their birthday doesn't match anyone already there.

Show Answer

Just 23 people.

With 23 people in the room, the probability that at least two share a birthday is roughly 50.7%. By 70 people, it climbs above 99.9%.

This feels fundamentally wrong because we instinctively compare against our own birthday and assume there is a 1 in 365 chance. Instead, we should be comparing every possible pair of people in the room. With 23 people there are 253 unique pairs, and each one is an independent chance for a match.

I wrote a Python script that verifies this analytically and through simulation.

The math (roughly) is as follows:

Work out the probability that no two people share a birthday, then subtract from 1.

Each new person entering the room must have a birthday that avoids everyone already there:

  • Person 1: 365/365 (no constraint)
  • Person 2: 364/365 (must miss person 1's birthday)
  • Person 3: 363/365 (must miss persons 1 and 2)
  • Person n: (365 - n + 1) / 365

Multiply these together:

P(no match) = (365 × 364 × 363 × ... × (365 - n + 1)) / 365^n

For n = 23 this comes out to roughly 0.4927, so:

P(at least one match) = 1 - 0.4927 = 0.5073

The Petri Dish

Source: Unknown, first encountered in an interview and widely circulated on social media

A bacteria in a petri dish doubles every minute and is full in an hour. At what minute is the petri dish half full?

Show Hint How do you find half of any quantity, given the maximum quantity?
Show Solution 59 minutes.

If the dish is full at 60 minutes and the bacteria double every minute, it was half full exactly one minute before that. Seems obvious now, right?

The Brakeman, Fireman, and Engineer

Source: Oswald Jacoby and William Benson's Mathematics for Pleasure (1962)

A train has three crew members: a brakeman, a fireman, and an engineer. Their last names are Smith, Jones, and Robinson, in no particular order. Three passengers on the same train happen to share those names: Mr. Smith, Mr. Jones, and Mr. Robinson.

You are given the following clues:

What is the engineer's last name?

Show Hint

Start by figuring out who the brakeman is. Work through each name and see which ones can be eliminated.

The salary clue is key: $20,000 divided by 3 is not a whole number. What does that tell you about Mr. Jones's relationship to the brakeman?

Show Answer
  1. Smith beats the fireman at billiards, so Smith cannot be the fireman. He must be either the brakeman or the engineer.
  2. The brakeman lives halfway between Detroit and Chicago. He also has a neighbor who earns three times as much as he does.
  3. The neighbor cannot be Mr. Robinson, because Mr. Robinson lives in Detroit. The neighbor also cannot be Mr. Jones, because Mr. Jones earns $20,000 and $20,000 is not divisible by 3. So the brakeman's neighbor must be Mr. Smith.
  4. With Mr. Smith established as the brakeman's neighbor (living near the halfway point), and Mr. Robinson in Detroit, the passenger in Chicago must be Mr. Jones. Clue 6 says the Chicago passenger shares a last name with the brakeman, so the brakeman's last name is Jones.
  5. Smith is not the fireman (step 1) and not the brakeman (that's Jones). Smith must be the engineer.
  6. Robinson is the only name left, so Robinson is the fireman.

The brakeman is Jones, the fireman is Robinson, and the engineer is Smith.

The Language Club

Source: Unknown

A high school language club has members who study French, German, and Spanish, with some studying more than one. You are given the following information:

How many members does the club have in total? How many study exactly one language?

Show Hint

Use the inclusion-exclusion principle. When you add up all three groups, students who study two languages get counted twice, and students who study all three get counted three times. You need to subtract and add back accordingly.

Show Answer

The club has 39 members total. 14 study exactly one language.

Total = French + German + Spanish - (French & Spanish) - (French & German) - (Spanish & German) + (all three) Total = 21 + 20 + 26 - 12 - 10 - 9 + 3 = 39

  • Only French: 21 - 12 - 10 + 3 = 2
  • Only German: 20 - 10 - 9 + 3 = 4
  • Only Spanish: 26 - 12 - 9 + 3 = 8

2 + 4 + 8 = 14

Knights and Knaves

Source: What Is the Name of This Book by Raymond Smullyan (1978)

On a certain island, every inhabitant is either a knight or a knave. Knights always tell the truth; knaves always lie. They look identical.

A visitor meets three islanders and asks each whether they are a knight or a knave. The first mutters something too quiet to hear. The second says: "He claims to be a knight." The third says: "The second one is lying."

Only one of the three is a knave. Who is who?

Show Hint

Think about what any islander, knight or knave, would say if asked whether they are a knight or a knave. Does that tell you anything about what the first person must have said? If you are still struggling, consider building out a truth table. Another hint: Assume that every islander will want you to think they are telling the truth.

Show Answer

The first and second are knights. The third is the knave.

Any islander, asked whether they are a knight or a knave, will claim to be a knight. A knight says so truthfully; a knave lies and says it anyway. So whatever the first person said, they definitely claimed to be a knight. The second person described that correctly, which means the second person told the truth and is therefore a knight.

The third person says the second is lying. But the second is a knight (as established), so the third person is wrong. That makes the third person the knave.

Four Men and a Crime

Source: Unknown

Four suspects each make one statement about who committed a crime:

Part 1: If exactly one of these statements is true, who is guilty?

Part 2: If exactly one of these statements is false, who is guilty?

Show Hint

Work by assumption. Pick a suspect, assume they are guilty, and check how many statements come out true. If it matches the constraint, you have your answer.

Show Answer

Part 1 (only one statement is true): Gus is guilty.

If Gus did it: Archie is wrong (false), Dave is wrong (false), Gus's claim that he is innocent is wrong (false), and Tony is right that Dave lied (true). That gives exactly one true statement.

Part 2 (only one statement is false): Dave is guilty.

If Dave did it: Archie is right (true), Dave's claim that Tony did it is wrong (false), Gus is right that he didn't do it (true), and Tony is right that Dave lied (true). That gives exactly one false statement.

The Smudged Faces

Source: J.E. Littlewood (1953)

Three travelers exit a tunnel. Unbeknownst to any of them, all three came out with a smudge of soot on their forehead. A fellow passenger points this out and proposes a way to figure out whether you're smudged without a mirror.

He asks each of the three to look at the other two and raise their hand if they see at least one smudge. All three raise their hands immediately.

The passenger then says: "As soon as you know for certain whether your own forehead is smudged, drop your hand."

After a brief pause, one of the travelers drops their hand and says, "I know mine is smudged." How did they figure it out?

Show Hint

Assume for a moment that your forehead is clean. What would the other two travelers see? What would each of them be able to deduce from that?

Show Answer

The traveler reasoned as follows:

Suppose my forehead is clean. Then each of the other two sees one smudged face (the third person) and one clean face (mine). Both still raise their hands, because they each see at least one smudge. But now each of them should be able to reason: "The person I see with a smudge raised their hand because they see a smudge somewhere. The only smudge they could be seeing is mine. So I must be smudged." Each would immediately know and drop their hand.

But neither of them dropped their hand right away. That means the assumption is wrong: my forehead cannot be clean. It must be smudged.

The first traveler to complete this chain of reasoning dropped their hand.

The Unexpected Hanging Paradox

Source: Martin Gardner (1963)

A judge sentences a prisoner on Saturday, telling them: "You will be hanged at noon on one day during the coming week. You will not know which day until the morning of the execution."

The prisoner reasons through this carefully. They cannot be hanged on Saturday (the last possible day), because by Friday night, if they had not yet been hanged, Saturday would be the only option remaining and would no longer be a surprise. With Saturday ruled out, Friday becomes the last possible day, and the same logic applies. Working backward through the week, the prisoner concludes the hanging cannot happen on any day and goes to sleep relieved.

Then they are hanged on Wednesday, completely surprised.

Where did the prisoner's reasoning go wrong?

Show Hint

The prisoner's argument relies on eliminating days one at a time from the end of the week. But each elimination step assumes the prisoner has already successfully ruled out all later days. Is that assumption actually solid?

Show Answer

The prisoner's reasoning is flawed, though pinpointing exactly why is surprisingly tricky and has been debated by logicians for decades.

The key problem is that the backwards elimination chain is not as airtight as it seems. The Saturday argument is however valid: if it's Friday night and no hanging has occurred, Saturday is no longer a surprise. But the Friday argument depends on Saturday already being ruled out. That elimination only holds if the prisoner can be certain Saturday will not be used, and that certainty requires the judge's statement to be known to be true in advance.

The judge's statement is a prediction about a future event. The prisoner can know it is true only after the fact, not before. Each step of the backwards induction works from the assumption that the prisoner has already proven the judge cannot use the remaining days, but that proof depends on steps that haven't been established yet. So the argument is circular.

In practice, the judge can carry out the sentence, and the prisoner will be surprised because the prisoner's logic collapses under its own self-referential weight.

The Two Guards

You are a prisoner in a room with two doors and two guards. One door leads to freedom; the other leads to a hangman. The guards know which is which. One guard always tells the truth, and the other always lies. You do not know which is which, but the guards know each other. You may ask one guard a single question.

What do you ask to find the door that leads to freedom?

Show Hint

A direct question like "which door leads to freedom?" will not work, because you cannot trust the answer without knowing who you are talking to.

Think about how you might route the question through both guards at once, so that their opposing tendencies cancel each other out.

Show Answer

Ask either guard: "If I asked the other guard which door leads to freedom, what would they say?" Then take the opposite door.

It works regardless of which guard you ask because:

  • If you ask the truth-teller, they honestly report what the liar would say. The liar would point to the wrong door, so the truth-teller tells you: the wrong door.
  • If you ask the liar, they lie about what the truth-teller would say. The truth-teller would point to the right door, so the liar tells you: the wrong door.

Both guards point to the wrong door, so you can safely go through the other one.

Alternative formulations that work by the same double-negation logic:

  • "Which door would the other guard say leads to the hangman?" Then go through the door they point to (no inversion needed this time).
  • "If I asked you which door leads to freedom, what would you say?" Then go through the door they indicate. The liar is forced to lie about their own lie, which cancels out and lands them on the truth.
  • "If you were the other guard, which door would you point to?" Then take the opposite door.

The Lion and the Unicorn

Source: What Is the Name of This Book by Raymond Smullyan (1978)

A girl meets a lion and a unicorn in a forest. The lion lies on Mondays, Tuesdays, and Wednesdays, and tells the truth the other days. The unicorn lies on Thursdays, Fridays, and Saturdays, and tells the truth the other days.

The lion says: "Yesterday I was lying." The unicorn says: "So was I."

What day is it?

Show Hint

Work out separately which days each creature could make the statement "Yesterday I was lying" without contradicting their own schedule. Then find the day that appears on both lists.

Remember: the statement can be consistent two ways. Either the creature is telling the truth (in which case yesterday really was a lying day), or the creature is lying (in which case yesterday was actually a truth-telling day).

Show Answer

It is Thursday.

Work out which days each creature can plausibly say "Yesterday I was lying":

The lion (lies Mon/Tue/Wed, tells the truth on Thu/Fri/Sat/Sun)

  • If he was telling the truth today, yesterday must have been a lying day (Mon/Tue/Wed), making today Tue/Wed/Thu. The lion tells the truth only on Thu from that set. Thursday is a candidate.
  • If he is lying today, yesterday must have been a truth day (Thu/Fri/Sat/Sun), making today Fri/Sat/Sun/Mon. The lion lies only on Mon from that set. Monday is a candidate.

The lion can say this consistently on **Thursday or Monday.

The Unicorn (lies Thu/Fri/Sat, tells the truth on Sun/Mon/Tue/Wed):

  • If he is telling the truth today, yesterday must have been a lying day (Thu/Fri/Sat), making today Fri/Sat/Sun. The unicorn tells truth only on Sun from that set. Sunday is a candidate.
  • If he is lying today, yesterday must have been a truth day (Sun/Mon/Tue/Wed), making today Mon/Tue/Wed/Thu. The unicorn lies only on Thu from that set. Thursday is a candidate.

The unicorn can say this consistently on Sunday or Thursday.

The only day that works for both is Thursday. On Thursday, the lion is telling the truth (Wednesday was a lying day), and the unicorn is lying (Wednesday was actually a truth-telling day for the unicorn).

The Mislabeled Boxes

Source: Apple interview

Three closed boxes are labeled "Apples," "Oranges," and "Apples and Oranges." One box contains only apples, one contains only oranges, and one contains both. Every label is wrong.

You may pick exactly one fruit from one box, without looking inside. How do you determine what is in each box?

Show Hint

Think about which box gives you the most information from a single fruit. One of the three labels, by being wrong, tells you something very specific about what that box cannot contain.

Show Answer

Pick a fruit from the box labeled "Apples and Oranges."

Since every label is wrong, this box cannot contain both. It holds either only apples or only oranges. One fruit tells you which.

From there, the other two boxes resolve by elimination:

  • If you draw an apple: that box holds only apples. The box labeled "Apples" can't hold apples (wrong label) and can't hold the mixed contents (those belong to your identified box), so it must hold only oranges. That leaves the box labeled "Oranges" as the mixed box.
  • If you draw an orange: that box holds only oranges. The box labeled "Oranges" can't hold oranges and can't hold the mixed contents, so it must hold only apples. The box labeled "Apples" is the mixed box.

One fruit is enough because the "Apples and Oranges" box is the only one whose wrong label constrains it to a single fruit type, and once it is identified, the remaining two boxes have only one valid assignment.

The Day Before Two Days After

Source: Unknown

The day before two days after the day before tomorrow is Sunday. What day is it today?

Show Hint

Unpack the phrase from the inside out, substituting "today + N days" at each step.

Show Answer

It is Saturday.

Working from the inside out, letting today = T:

  1. "tomorrow" = T + 1
  2. "the day before tomorrow" = T + 1 - 1 = T
  3. "two days after [that]" = T + 2
  4. "the day before [that]" = T + 2 - 1 = T + 1

So T + 1 = Sunday, which means today is Saturday.

The Farmer, Fox, Chicken, and Grain

Source: Alcuin of York, Propositiones ad Acuendos Juvenes (c. 800 AD)

A farmer stands at the bank of a river with a fox, a chicken, and a bag of grain. He needs to get all three across in a small boat that can carry only himself and one other item at a time.

If left alone together, the fox will eat the chicken, and the chicken will eat the grain. The farmer cannot leave any incompatible pair unsupervised on either bank.

How does he get everything across safely?

Show Hint

The farmer does not have to move items in one direction only. Taking something back across is allowed, and may be necessary.

Show Answer

One solution (there are two):

  1. Take the chicken across. Leave it on the far bank.
  2. Return alone.
  3. Take the fox across.
  4. Bring the chicken back.
  5. Take the grain across.
  6. Return alone.
  7. Take the chicken across.

Taking the chicken back may feel like moving backwards, but it is the only way that you can keep the fox and grain separated while you move the grain across.

The second solution swaps steps 3 and 5. Take the grain first, then the fox. It is identical otherwise.

The Blind Man's Pills

Source: Unknown

A blind man is stranded alone on a deserted island. He has two blue pills and two red pills, and does not know which is which. Each feel the exact same. He must take exactly one red pill and one blue pill to survive. Taking any other combination will kill him. How does he survive?

Show Hint

He cannot tell the pills apart by sight, but he does not need to. Think about whether there is a way to guarantee the right dose without identifying any individual pill.

Show Answer

He breaks each of the four pills in half and takes one half of every pill.

The four halves he swallows add up to exactly one full blue pill and one full red pill, regardless of which half came from which pill. The other four halves are discarded.

The Three Daughters

Source: MIT (1940s)

A man tells you that he has three daughters, and asks you to determine there ages.

He first tells you the product of their ages is 36. This is not enough info, so he adds that the sum of their ages equals his house number. You know the house number, but still cannot figure it out. Finally he says his eldest daughter lives upstairs and loves ice cream. Now you can solve it.

How old are the three daughters?

Show Hint

List every combination of three whole numbers whose product is 36, then calculate the sum for each. The fact that you knew the house number but still could not determine the ages is itself a clue. What does that tell you about the house number?

Show Answer

The daughters are 2, 2, and 9.

Start by listing every combination of three positive integers with a product of 36, along with their sums:

Ages Sum
1, 1, 36 38
1, 2, 18 21
1, 3, 12 16
1, 4, 9 14
1, 6, 6 13
2, 2, 9 13
2, 3, 6 11
3, 3, 4 10

Every sum is unique except 13, which appears twice: (1, 6, 6) and (2, 2, 9). Since you knew the house number but still could not determine the ages, the house number must be 13. Any other number would have pointed to a unique answer.

That leaves two candidates. The final clue resolves it: the only part that we care about is that the man has an eldest daughter, meaning one daughter is strictly older than the others. (1, 6, 6) has two daughters tied for oldest, so there is no single eldest. (2, 2, 9) has a clear eldest.

The daughters are therefore 2, 2, and 9.

The Blindfolded Coins

Source: Apple interview

You are blindfolded. Ten coins are placed on a table in front of you, exactly 5 heads up and 5 tails up, in an arrangement you do not know. You can touch and move coins freely but cannot tell heads from tails by feel. You may flip coins as many times as you like.

Divide the coins into two groups that each contain the same number of heads-up coins.

Show Hint

You do not need to identify a single coin correctly. Think about what happens algebraically when you separate a group of 5 and flip every coin in it, regardless of which specific coins ended up in that group.

Show Answer

Pick any 5 coins, put them in a separate group, and flip all 5.

Say you happened to grab k heads. After flipping, your group has (5 - k) heads. The group left on the table also has (5 - k) heads. Both match no matter the value of k.

Try it out!

One Hundred Prisoners and Hats

Source: Unknown

One hundred prisoners stand in a single-file line, all facing the same direction. Each wears a hat that is either red or black. Every prisoner can see the hats of everyone in front of them but not their own hat or any hats behind them.

Starting from the back of the line, each prisoner must state the color of their own hat out loud. A correct guess means survival; an incorrect guess means execution. Before the process begins, the prisoners may agree on a strategy. Once questioning starts, no communication is allowed beyond saying "red" or "black."

What strategy guarantees the most survivors, and how many are guaranteed?

Show Hint

The last prisoner in line can see all 99 hats in front of them. They cannot save themselves with certainty, but they can encode something in their answer that gives every other prisoner the information they need. What single property of a set of hats can be conveyed in one word?

Show Answer

99 are guaranteed to survive. The last prisoner is a coin flip.

The trick is that before lining up, everyone agrees that the last prisoner will count the red hats he/she can see. If the count is odd, they say "red." If it's even, they say "black." Their own hat is just a guess, they are using their turn to pass a message.

Every prisoner afterword knows whether the red hats ahead add up to an odd or even number. So each prisoner must simply count the red hats they can see in front, then add this number to the number of "red" answers they have already heard. If the total matches the signal, their own hat is black. If it doesn't, their hat is red. One of those two is always right.

The last prisoner can't use the trick themselves because there is nobody behind them to start it.

Einstein's Riddle

Source: Widely attributed to Albert Einstein, though this has never been verified. Also known as the Zebra Puzzle.

Five houses sit in a row. Each is painted a different color and is occupied by a person of a different nationality. Each person drinks a different beverage, smokes a different brand, and keeps a different pet. No two people share any attribute.

Here are the clues:

  1. The Brit lives in the red house.
  2. The Swede keeps dogs.
  3. The Dane drinks tea.
  4. The green house is immediately to the left of the white house.
  5. The green house owner drinks coffee.
  6. The person who smokes Pall Mall keeps birds.
  7. The owner of the yellow house smokes Dunhill.
  8. The person in the center house drinks milk.
  9. The Norwegian lives in the first house.
  10. The person who smokes Blends lives next to the cat owner.
  11. The horse owner lives next to the Dunhill smoker.
  12. The person who smokes BlueMaster drinks beer.
  13. The German smokes Prince.
  14. The Norwegian lives next to the blue house.
  15. The Blends smoker lives next to the water drinker.

Who owns the fish?

Show Hint

Start with what you can pin down absolutely. Clues 8 and 9 fix two positions immediately. Clue 4 restricts where the green and white houses can go. Build a grid with houses 1 through 5 across the top and attributes down the side, then fill in what you can derive from each clue, revisiting earlier clues as new cells are filled.

Show Answer

The German owns the fish.

Working through the grid:

  • From clue 9: Norwegian is in house 1.
  • From clue 14: house 2 is blue.
  • From clue 8: house 3 has milk.
  • From clue 4: green/white must be houses 4/5 (green immediately left of white).
  • From clue 5: green house (4) drinks coffee.
  • Houses 1 and 3 are neither green, white, nor blue. House 3 is not red (Brit is red, and we can rule that out shortly). That leaves house 1 as yellow, house 3 as red.
  • From clue 1: Brit is in house 3.
  • From clue 7: Norwegian (house 1) smokes Dunhill.
  • From clue 11: horse owner is next to Dunhill smoker (house 1), so horse is in house 2.
  • From clue 3: Dane drinks tea. Tea is not in house 3 (milk) or 4 (coffee), and house 1 is Norwegian. Dane is in house 2 or 5. House 5 has white house. Checking remaining beverages: house 1 gets water or beer. From clue 15: Blends smoker is next to water drinker. From clue 12: BlueMaster smoker drinks beer. Working through: Dane is in house 2 (drinks tea).
  • From clue 13: German smokes Prince. German is not in house 1 (Norwegian), 2 (Dane), or 3 (Brit). German is in house 4 or 5.
  • Remaining nationality is Swede, in house 4 or 5. From clue 2: Swede keeps dogs.
  • From clue 6: Pall Mall smoker keeps birds. From clue 12: BlueMaster smoker drinks beer. Beer is in house 1 or 5. House 1 drinks water or beer; from clue 15 the Blends smoker neighbors the water drinker. If house 1 drinks beer, the BlueMaster is in house 1, but house 1 smokes Dunhill. Contradiction. So house 1 drinks water and house 5 drinks beer.
  • From clue 12: house 5 smokes BlueMaster. From clue 13: German smokes Prince, not BlueMaster, so German is in house 4. Swede is in house 5.
  • From clue 15: Blends smoker neighbors water drinker (house 1), so Blends is in house 2.
  • From clue 10: Blends smoker (house 2) neighbors cat owner, so cats are in house 1 or 3.
  • From clue 6: Pall Mall smoker keeps birds. Remaining smokes for houses 3 and 4: Pall Mall and Prince. German (house 4) smokes Prince, so house 3 smokes Pall Mall and keeps birds.
  • From clue 10: cats in house 1 or 3. House 3 has birds, so cats are in house 1.
  • Swede (house 5) keeps dogs. House 4 (German) has the fish.
House 1 2 3 4 5
Color Yellow Blue Red Green White
Nationality Norwegian Dane Brit German Swede
Beverage Water Tea Milk Coffee Beer
Smoke Dunhill Blends Pall Mall Prince BlueMaster
Pet Cats Horses Birds Fish Dogs