Learn AP Comp Sci

Problem of the Day

Thursday, January 1, 2026


Problem:

One common system for controlling traffic flow involves three lights--a red light, yellow light, and green light--to indicate three traffic conditions, or states: "stop", "caution", and "go." A computer scientist waiting in a car at one of these lights realizes that the system, by allowing for more than a single light to be turned on at the same time, could actually be used to indicate as many as 8 different conditions:

  1. no lights on
  2. red light only on
  3. yellow light only on
  4. red and yellow light on
  5. etc.
  6. red, yellow, and green lights all on

Based on this realization, what minimum number of lights would be necessary for a traffic light to indicate the three conditions "stop", "caution", and "go."? And what maximum number of states could be indicated with a system of five traffic lights (for example red, orange, yellow, green, blue)?

Minimum lights needed to indicate 3 statesNumber of states possible with 5 lights
a.25
b.231
c.331
d.232
e.332

Show solution:

The correct answer is d. The lights, regardless of their individual color, can be considered as a binary system in which each light is either on or off. The number of states that can be indicated by a single light is 2, with the light either being on or off—with a single light we can count from 0 to 1. With two lights, we can count 0, 1, 2, 3 in binary—four states, which is sufficient to indicate three states of traffic control.

We see that the number of states, then, is just 2 raised to whatever number of lights we have. 21 is two states, 22 is four states, 23 would be 8 states... and 25, for 5 lights, would be 32 different states.