AP CSA FRQ Guide

2019 FRQ 4: LightBoard

Write two LightBoard methods. The constructor fills a 2D boolean grid so each light is on with a given probability. The evaluation method counts on-lights in a column and decides whether a specific light should be on in the next step.

2D Arrays and Random Booleans22 minute target2D arraysconstructorsMath.randomnested loopscolumn counts

Skills Tested

What this FRQ is really practicing

2D arraysconstructorsMath.randomnested loopscolumn counts

Treat these skills as the study checklist. If any tag feels shaky, review that topic before attempting the full written response.

Starter Approach

How to begin without copying a solution

  1. 1Constructor: create the lights array with numRows rows and numCols columns.
  2. 2Use Math.random so each cell is true with probability 0.40 and false otherwise.
  3. 3Part B: count how many lights in the specified column are currently on.
  4. 4If lights[row][col] is on, return false when the column on-count is even, otherwise true.
  5. 5If lights[row][col] is off, return true when the column on-count is divisible by 3, otherwise false.

Write a first attempt before revealing any solution outline. Most AP CSA FRQ progress comes from tracing your own code and finding the missing case.

Common Mistakes

Mistakes to watch for while writing

Using one random value for the entire board instead of one per cell.
Reversing the probability and making lights true 60 percent of the time.
Counting on-lights across a row instead of down the specified column.
Forgetting that evaluateLight should not change the lights array.
Applying the on-light rule and off-light rule to the wrong current state.

Self Check

Review questions before you submit

Defines the LightBoard constructor with row and column counts.

The constructor receives numRows and numCols.

Creates the lights 2D boolean array using numRows and numCols.

Use new boolean[numRows][numCols].

Uses nested loops to initialize every cell.

Each light should receive its own random result.

Uses Math.random to generate the on/off state.

Math.random() < 0.40 gives true about 40 percent of the time.

Uses the 0.40 probability threshold.

Each light should be on with probability 0.40.

Defines evaluateLight with boolean return type and row/col parameters.

Part B returns the next-state decision for one light.

Traverses the specified column across all rows.

Loop over row indexes and keep col fixed.

Counts lights that are currently on in the specified column.

Increment the count for true values.

Practice Links

Where to go next