Lesson goal: Truth-Tellers, Liars, and Alternators (AMC 10A Logic Puzzle)

Previous: Knights and Knaves logic puzzles | Home | Next: Contest Map Coloring: Five Regions

On Halloween, $31$ children walk into the principal's office asking for candy. They can be classified into three distinct personality types:
  • Truth-tellers: Always tell the truth on every question.
  • Liars: Always lie on every question.
  • Alternaters: Alternate between lying and telling the truth. They arbitrarily choose their first response (either a lie or the truth), and each subsequent statement has the opposite truth value from its predecessor.
The principal asks everyone the same three questions in order:
  1. "Are you a truth-teller?" — $22$ children answer yes and each receives a piece of candy.
  2. "Are you an alternater?" — $15$ children answer yes and each receives a piece of candy.
  3. "Are you a liar?" — $9$ children answer yes and each receives a piece of candy.
The Contest Question (2022 AMC 10A, Problem #12):
How many pieces of candy in all did the principal give to the children who always tell the truth?


Analyzing Response Patterns by Category

To solve this with logic, let's analyze how each category of child must answer the three questions:
  1. Truth-Tellers ($T$): Must tell the truth to all three questions.
    • Q1 ("Are you a truth-teller?"): Statement is true $\implies$ answers yes (receives candy).
    • Q2 ("Are you an alternater?"): Statement is false $\implies$ answers no.
    • Q3 ("Are you a liar?"): Statement is false $\implies$ answers no.
    • Pattern: [yes, no, no] — each truth-teller receives exactly $1$ piece of candy.
  2. Liars ($L$): Must lie to all three questions.
    • Q1 ("Are you a truth-teller?"): Truth is false $\implies$ lies: yes (receives candy).
    • Q2 ("Are you an alternater?"): Truth is false $\implies$ lies: yes (receives candy).
    • Q3 ("Are you a liar?"): Truth is true $\implies$ lies: no.
    • Pattern: [yes, yes, no] — each liar receives $2$ pieces of candy.
  3. Alternaters starting with Truth ($A_t$): Pattern of truthfulness: [Truth, Lie, Truth].
    • Q1 ("Are you a truth-teller?"): Reality is false. Tells truth $\implies$ answers no.
    • Q2 ("Are you an alternater?"): Reality is true. Must lie $\implies$ answers no.
    • Q3 ("Are you a liar?"): Reality is false. Tells truth $\implies$ answers no.
    • Pattern: [no, no, no] — receives $0$ pieces of candy!
  4. Alternaters starting with a Lie ($A_l$): Pattern of truthfulness: [Lie, Truth, Lie].
    • Q1 ("Are you a truth-teller?"): Reality is false. Must lie $\implies$ answers yes (receives candy).
    • Q2 ("Are you an alternater?"): Reality is true. Tells truth $\implies$ answers yes (receives candy).
    • Q3 ("Are you a liar?"): Reality is false. Must lie $\implies$ answers yes (receives candy).
    • Pattern: [yes, yes, yes] — receives $3$ pieces of candy!

The Deductive System

Looking at who answered yes to each question:
  • Question 3: Only $A_l$ answered yes $\implies A_l = 9$.
  • Question 2: Liars ($L$) and $A_l$ answered yes $\implies L + A_l = 15 \implies L = 15 - 9 = 6$.
  • Question 1: Truth-tellers ($T$), Liars ($L$), and $A_l$ answered yes $\implies T + L + A_l = 22 \implies T = 22 - 6 - 9 = 7$.
  • Total children: $T + L + A_t + A_l = 31 \implies 7 + 6 + A_t + 9 = 31 \implies A_t = 9$.
  • Candy for Truth-Tellers: $T \times 1 = 7 \times 1 = 7$ pieces of candy!
Let's see how Prolog expresses this reasoning and computes the solution!
total_children(31). q1_yes(22). q2_yes(15). q3_yes(9).
AltLie is Q3, Liars is Q2 - AltLie.

TruthTellers is Q1 - Liars - AltLie.

AltTruth is Total - TruthTellers - Liars - AltLie.

CandyForTruthTellers is TruthTellers * 1.

goal: solve(TruthTellers, Liars, AltTruth, AltLie, CandyForTruthTellers).
Move the mouse over a dotted box for more information.

  • Declarative Reasoning: In Prolog, you specify the logical relationships between facts and unknowns. Prolog executes the deductions in order and unifies the variables with their unique solutions.
  • AMC 10A Result: The answer to Problem #12 is (A) 7.

Now you try. Replace the ???? placeholders with the deduction expressions (Q3, Q2 - AltLie, Q1 - Liars - AltLie, Total - TruthTellers - Liars - AltLie, and TruthTellers * 1). Click Run to deduce the answer (7 pieces of candy)!

Type your code here:


See your results here: