Case-based lecture: you attempt, we discuss, then we reveal.
cs-001, cs-002, cs-003, cs-004A cafe card gives every 10th drink free (buy 9, the 10th costs nothing). Price 3.50 per paid drink; the student wants 22 drinks this month. What do they pay?
Expected: (20, 2, 70.0)
Cost: O(wanted) time, O(1) space; a closed form (paid = wanted - wanted // 10) exists and is worth deriving as a check.
An elevator serves requests in press order: [3, 7, 3, 1, 5]. 3 s per floor moved, 6 s per stop (including the first). Total time?
Expected: 72
Cost: O(n) time for n requests; the *optimisation* of ordering is a different (harder) problem, previewed in Block III.
Machine A sells at 2.00, exact coins only. Machine B sells at 2.30 and gives change. The student holds specific coins. Write decision rules covering exact match, overpay possible, overpay impossible, and B sold out.
Expected: machine B / machine A / no purchase (per the three traces)
Cost: Constant time; the difficulty is specification completeness, not cost.
Fines: 0.50/day for days 1-7, 1.00/day for days 8-30, cap 10.00. Returned on day 5, day 12, day 40 - and on the due date itself?
wanted = 22
price = 3.50
paid = wanted - wanted // 10
free = wanted // 10
print(paid, free, paid * price)Expected: 2.50; 8.50 (our reading); 10.00; due-date return 0.00
Cost: Constant time. The pedagogical content is the two contested readings, not the arithmetic.
A cafe loyalty card: buy 9 drinks, get 1 free. Given the price of a drink and how many drinks a student wants over a month, how much will they actually pay? Must decide what happens when a free drink is 'earned' mid-month.
**Input:** price 3.50 per drink; the student wants 22 drinks this month**Output:** 20 paid drinks, total 70.00 (2 free drinks earned: the 10th and the 20th drink)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-001 — not embedded in this deck.
An office elevator stops at every requested floor in the order buttons were pressed. Decide the total travel time for a list of floor requests, then debate a better ordering policy.
**Input:** floors requested in press order: [3, 7, 3, 1, 5]; 3 s per floor move; 6 s per stop**Output:** travel 3->7->3->1->5 moves 14 floors = 42 s; stops 5 = 30 s; total 72 sSolve 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-002 — not embedded in this deck.
Two machines sell the same drink for different prices; one accepts exact coins only, the other gives change. Write precise rules for which machine a student should use given the coins they hold.
**Input:** drink 2.00; student holds coins 2.00 exactly vs drink 2.30 with coins 2.50 (needs change)**Output:** exact-coin machine when coins match a price; change machine otherwise; never the exact machine if it means overpayingSolve 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-003 — not embedded in this deck.
A library charges fines with a tiered rule (per day, capped, and waived under conditions). Turn a vague policy into an exact formula, including what happens on the return day itself.
**Input:** 0.50/day for days 1-7, 1.00/day for days 8-30, cap 10.00; returned on day 5, on day 12, on day 40**Output:** 2.50; 7.00 (5 charged days: 7+5x1.00); 10.00 (capped); same-day return 0.00Solve 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-004 — not embedded in this deck.