Case-based lecture: you attempt, we discuss, then we reveal.
cs-057, cs-058, cs-133, cs-059, cs-060100 lockers, 100 students; student i toggles every i-th locker. Which lockers end open?
open_lockers = [False] * 101
for student in range(1, 101):
for locker in range(student, 101, student):
open_lockers[locker] = not open_lockers[locker]
squares = [n for n in range(1, 101) if open_lockers[n]]
print(squares[:5], squares[-1], len(squares))Expected: open lockers: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
Cost: Simulation O(n log n) (harmonic sum); the mathematical answer is O(1) - reasoning beats brute force.
5 students line up for a photo; P and Q refuse to stand together. How many acceptable lineups?
import math
total = math.factorial(5)
blocked = math.factorial(4) * 2
print(total, blocked, total - blocked)Expected: 72
Cost: O(1) with the counting argument; enumerating 120 lineups is fine too but does not scale.
A committee of 4 from 6 CS and 4 DS students. How many committees include at least one of each programme?
import math
c = math.comb
total = c(10, 4)
forbidden = c(6, 4) + c(4, 4)
print(total, forbidden, total - forbidden)Expected: 194
Cost: O(1) arithmetic via factorials; a brute-force enumeration would touch all 210 committees.
How many people are needed for a shared-birthday chance above 50%, assuming 365 equally likely days and no leap days?
p = 1.0
n = 0
while p >= 0.5:
n += 1
p *= (366 - n) / 365
print(n, round(1 - p, 3))Expected: 23 people (P(shared) ~ 50.7%)
Cost: O(answer) for the product, O(trials x n) for the simulation - both trivial here.
100 lockers, 100 students, student i toggles every i-th locker. Which remain open? Counting by reasoning, then verify with a tiny simulation.
**Input:** 100 lockers, 100 students; student i toggles lockers divisible by i**Output:** open lockers are perfect squares: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100Solve 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-057 — not embedded in this deck.
Count lineups of 5 students where two specific students refuse to stand together. Inclusion-exclusion in plain language first.
**Input:** 5 students; students P and Q refuse to stand together**Output:** 5! = 120; together (block): 4! x 2 = 48; apart: 120 - 48 = 72Solve 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-058 — not embedded in this deck.
The university shuttle poster says: **"a bus every ten minutes."** The operational facts:
**Input:** the schedule, loop legs, fleet size**Output:** `departures 0, 10, 25, 35, 50, 60` — gaps `10, 15, 10, 15,10` — verdict + noticeSolve for the worked instance first. Then ask what would change if onePseudocode, 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-133 — not embedded in this deck.
From 6 CS and 4 DS students, a 4-person committee must include at least one of each programme. Count compositions; then compute the probability a random draw satisfies it.
**Input:** 6 CS, 4 DS; committee of 4 with at least one of each programme**Output:** total C(10,4)=210; all-CS C(6,4)=15; all-DS C(4,4)=1; valid 210-16 = 194Solve 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-059 — not embedded in this deck.
How many students until two likely share a birthday? Derive the complement product, compute thresholds, and confirm by simulation. The classic that teaches complement thinking.
**Input:** n people, 365 equally likely birthdays (ignore leap days)**Output:** P(no shared) = 365/365 x 364/365 x ... ; n=23 gives P(shared) ~ 50.7%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-060 — not embedded in this deck.