Home/Study Plan/Logic Puzzles (Hats, Weighing, Liars)
๐Ÿง 

Brainteasers & Logic

Logic Puzzles (Hats, Weighing, Liars)

Medium3โ€“4 hrsLogicHatsDeductionWeighing

Overview

Logic puzzles test structured deductive reasoning under constraints. The key strategy: work backwards from what the LAST actor knows, or enumerate the information states explicitly. For hat problems: each person's strategy maps their observations to an action. For weighing: each weighing gives 3 outcomes, so n weighings can distinguish 3^n objects. The interview tests whether you can think systematically rather than randomly.

How to Recognize

  • โ†’Perfect logical agents who know everyone else is logical
  • โ†’'N prisoners, see everyone else's hat but not their own'
  • โ†’Weighing problems with a balance scale
  • โ†’Knights and knaves (liars and truth-tellers)

Step-by-Step Approach

  1. 1.Work backwards: what does the LAST person know? What can the FIRST deduce?
  2. 2.Use induction: solve n=1 case, then n=2, then generalize
  3. 3.Identify what information each agent can deduce from the situation itself
  4. 4.Each weighing partitions into 3 groups (balance scale: left heavy, balanced, right heavy)

Key Formulas

01NN weighings can distinguish among 3N3^N possibilities (balance scale)
0212 balls, 1 fake (unknown direction): need โŒˆlogโก3(36)โŒ‰=4\lceil \log_3(36) \rceil = 4... actually 3 weighings work
03Information: kk yes/no answers โ†’ 2k2^k distinguishable outcomes

Worked Examples

0Quick Example
12 balls, 1 different weight (unknown direction), 3 weighings on balance scale. Partition into groups of 4. First weighing reveals which group (L/R/balanced).

Problem

100 prisoners each wear a red or blue hat. In a line, each can see everyone in front. Starting from the back, each says 'red' or 'blue'. Guards execute anyone who's wrong. Strategy to save at least 99?

Solution

1

The last prisoner (sees all 99 others) uses their guess to communicate information to everyone else.

2

Strategy: last prisoner counts the number of red hats they see. If odd, say 'red'. If even, say 'blue'.

3

Now prisoner 99 knows: (a) parity announced by prisoner 100, (b) how many red hats they see in front. They can deduce their own hat.

4

Prisoner 99: if parity was 'odd' (meaning total reds in positions 1โ€“99 is odd) and they see even reds, their hat must be red. Continue this logic.

5

Every prisoner from 99 down to 1 can deduce their hat color with certainty.

6

Prisoner 100 has 50/50 chance (first to guess). Expected: 99.5 prisoners saved.

Answer

Parity strategy saves all but the last prisoner (50/50). The key: encode the global parity information in the first guess, then everyone deduces from the parity + what they see.

Common Mistakes

  • !

    Trying to solve the 12-ball problem by trial and error instead of systematic information counting.

  • !

    In hat puzzles, forgetting that each prisoner's DECISION (not just their guess) is visible to those behind them.

  • !

    Not thinking about what information each weighing gives: balance = fake not in these 8, left-heavy = fake is in left OR right (depending on setup).

Practice Problems

Click "Show Answer" to reveal
1

A bat and ball cost 1.10together.Thebatcosts1.10 together. The bat costs 1.00 more than the ball. How much does the ball cost?

Hint: Don't answer $0.10. Write the equation.
2

Three gods: Truth (always true), Lie (always lies), Random (random). You can ask 3 yes/no questions to identify each. How?

Hint: Classic puzzle โ€” use 'if I asked you X, would you say yes?' to get consistent answers from all three.

Only works in the Electron app

<webview> is an Electron-only tag. Run npm run electron:dev to use this.

25:00Focus
0

25 min focus ยท 5 min break ยท long break every 4 sessions

The Ultimate Grind