cs-033 — The Reading Log
| Field | Value |
|---|---|
| id | cs-033 |
| difficulty | Beginner |
| topics | aggregation, loops |
| lecture | lecture-09 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | none |
| objective | state inputs, outputs, and assumptions, then solve a small instance by hand |
| solution | held by the instructor; discussed after the attempt |
Problem
From a list of daily page counts, output total, average, best day, and days below target. The canonical running-total lecture case.
Your deliverable is the computed aggregates for the worked instance, the accumulator update rules, and one test input that breaks a careless initialisation. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: pages [12, 0, 25, 8, 30], target 10
- Output: total 75, average 15.0, best 30, below-target days 3 (0, 8, and... recount: 0,8 yes; 12 no; careful)
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- Average over ALL days or only reading days? Decide and state it - that choice changes the number.
- Every aggregate here is a small machine: state + update rule.
- The initial value is part of the algorithm, not a detail.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Which accumulator was hardest to get right, and what test would have caught the mistake?"
Constraints and assumptions
- Difficulty: Beginner (no prior experience assumed).
- Topics: aggregation, loops.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for a first attempt; partial answers with clear reasoning are worth more than silent struggling.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Recompute all aggregates in a second pass and argue which pass you would keep.