Case-based lecture: you attempt, we discuss, then we reveal.
cs-005, cs-006, cs-007, cs-008Read three numbers; output the largest. Make the pseudocode precise enough that a classmate translates it without questions.
Expected: 12 (and 7 for the tie case)
Cost: n - 1 comparisons for n numbers; can 2 compares ever suffice for 3 numbers? (No - a pigeonhole argument students can find themselves.)
Password valid when: 8-12 characters, at least one digit, starts with a letter. Output exactly one message naming the FIRST failing rule.
Expected: four different messages for the four traces
Cost: O(length) for the digit scan; the rest constant.
Pseudocode for buying a snack: insert coins until credit >= price, then vend and give change; refuse when sold out (before accepting money).
Expected: vend, change 0.20, stock 2 | sold out, coins returned (stock 0 case)
Cost: O(coins inserted). The real content is the state table: credit and stock per event.
Playlist A(pop), B(pop), C(jazz), D(pop), E(jazz). Order all songs once so no two same-artist songs are adjacent; state the repair rule when impossible.
a, b, c = 7, 12, 9
best = a
if b > best:
best = b
if c > best:
best = c
print(best)Expected: A, C, B, E, D
Cost: O(n) passes for the interleave; the feasibility bound is the intellectual content.
Read three numbers and output the largest. Trivial in words — the value is in writing pseudocode precise enough that a classmate could translate it without questions.
**Input:** 12, 7, 9**Output:** 12Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-005 — not embedded in this deck.
A password must be 8-12 characters, contain at least one digit, and start with a letter. Express the check as pseudocode with clear order of tests and a single output message.
**Input:** "klass7a!" (7 chars, no digit) vs "Password1" (9, digit, letter start) vs "1secure9" (starts with digit)**Output:** fail (too short, no digit); pass; fail (must start with a letter)Solve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-006 — not embedded in this deck.
Write pseudocode for buying a snack: insert coins until the price is met, handle overpayment with change, handle 'sold out'. Track machine state precisely.
**Input:** price 1.80; coins inserted 1.00, 1.00; machine stock 3**Output:** vend item, change 0.20, stock 2; then with stock 0: refuse and return coinsSolve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-007 — not embedded in this deck.
Write pseudocode for a shuffle that plays every song exactly once but never two songs by the same artist back-to-back. The interest is in stating constraints and repair steps precisely.
**Input:** playlist A(pop), B(pop), C(jazz), D(pop), E(jazz)**Output:** e.g. A, C, B, E, D - all songs once, no two same-artist adjacent; same-artist-majority needs a repair ruleSolve for the worked instance first. Then ask what would change if onenumber, name, or condition were replaced by something stranger.Pseudocode, flowchart or Python. State one assumption. Compare with your neighbour at minute 4.
Instructor: the reveal, the reasoning section and common wrong turns are in the instructor distribution for cs-008 — not embedded in this deck.