cs-039 — Template Mail-Merge
| Field | Value |
|---|---|
| id | cs-039 |
| difficulty | Intermediate |
| topics | strings, parsing |
| lecture | lecture-10 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | loops, lists, and tracing from lectures 1-6 |
| objective | choose the technique, trace it faithfully, and defend the boundary behaviour |
| solution | held by the instructor; discussed after the attempt |
Problem
Fill 'Dear {name}, ... {deadline} ...' templates from records, handling missing fields with a fallback. Splitting, joining, and safe replacement.
Your deliverable is the verdict for the worked instance, the normalisation rules you applied, and one input that exposes a missing rule. 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: template "Dear {name}, your {item} is due {deadline}."; record missing "item"
- Output: "Dear Ada, your [item] is due Friday." with a visible fallback marker
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
- Split on '{' and '}', replace known fields, mark unknown ones - never crash on missing data.
- Most string tasks are: normalise, then a simple check.
- Index arithmetic is where string bugs live — guard the ends first.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "Swap your example with a neighbour: does their edge case break your solution?"
Constraints and assumptions
- Difficulty: Intermediate (loops and lists assumed).
- Topics: strings, parsing.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for the plan and trace; finishing the details is a bonus, defending the method is the target.
- 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: Normalise the input differently and show the answer does (or does not) change.