cs-037 — Username Auditor
| Field | Value |
|---|---|
| id | cs-037 |
| difficulty | Beginner |
| topics | strings, validation |
| lecture | lecture-10 |
| 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
Check usernames against rules: length, allowed characters, no consecutive underscores. Walk characters and build verdicts.
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: "ada_2019" ok; "ada__love" fail (consecutive underscores); "9lives" fail; "ok" fail (short)
- Output: verdicts as above; rules: 5-16 chars, letters/digits/underscore only, no consecutive underscores, must start with a letter
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
- Check rules in an order that produces the most useful message first; walk once, flag once.
- 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: Beginner (no prior experience assumed).
- Topics: strings, validation.
- 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: Normalise the input differently and show the answer does (or does not) change.