Learn AP Comp Sci

Problem of the Day

Thursday, March 26, 2026


Problem:

A square fence can be constructed by placing a number of posts in the ground next to each other so that they form a border around an interior space. In the example shown here, a square fence, five posts to a side, requires 16 posts.

Which formula will always calculate the number of fence posts needed for a square fence of sides n × n, where n > 2?

  1. n * n - (n + 4)
  2. n * 4 - (n - 1)
  3. n * 4 - 4
  1. I only
  2. II only
  3. III only
  4. I and II only
  5. I and III only

Show solution:

The correct answer is c. For any given dimensions n × n, the number of fence posts needed is the perimeter, which is 4 × the length of each side less the 4 posts at the corners, or 4 * n - 4. Formulae I and II provide the correct value for a 5 × 5 fence, but don't work for fences of other sizes.