Case-based lecture: you attempt, we discuss, then we reveal.
cs-113, cs-114, cs-115, cs-116Two fair dice. Estimate P(sum = 8) by enumeration and by simulation; compare with the exact 5/36.
import random
random.seed(7)
exact = sum(1 for a in range(1, 7) for b in range(1, 7) if a + b == 8) / 36
hits = sum(1 for _ in range(10000) if random.randint(1, 6) + random.randint(1, 6) == 8)
estimate = hits / 10000
print(round(exact, 4), round(estimate, 3))Expected: exact 0.1389; simulated ~0.138 (seed 7, 10,000 trials)
Cost: O(trials); standard error shrinks as 1/sqrt(trials) - four times the trials buy two times the precision.
One server, arrivals every 2 minutes, service takes exactly 1 minute. Simulate 10 customers; what is the maximum wait, and does that match the analytical answer (0)?
free = 0
worst = 0
for i in range(10):
arrival = 2 * i
start = max(arrival, free)
worst = max(worst, start - arrival)
free = start + 1
print(worst)Expected: maximum wait: 0 minutes (matches the analytical answer)
Cost: O(customers); the analytical check cost nothing and caught nothing - which is the point of running it.
A quiz: answer 4-option questions, 0.25 penalty per wrong answer. Strategy A: answer everything. Strategy B: answer only if you can eliminate one option. Estimate expected scores per question.
import random
random.seed(11)
N = 100000
score_a = score_b = 0
for _ in range(N):
score_a += 1 if random.random() < 0.25 else -0.25
score_b += 1 if random.random() < 1 / 3 else -0.25
print(round(score_a / N, 4), round(score_b / N, 4))Expected: expected score per question: A ~ 0.0625, B ~ 0.167
Cost: O(N) per strategy; precision 1/sqrt(N) as always.
Simulate 10,000 rolls of two dice; compare the sum distribution to theory. Building the generator and trusting the sample.
**Input:** two dice, 10,000 rolls**Output:** sum 7 ~ 16.7% (6/36 exact); distribution matches theory within ~1%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-113 — not embedded in this deck.
One server, random arrivals: simulate waits under different arrival rates. See queueing behaviour emerge; locate the collapse point.
**Input:** arrivals Poisson-ish rate 4/hour, service 5/hour, simulate 400 hours**Output:** low waits at rho=0.8; collapse as rate approaches service capacity - queues are nonlinearSolve 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-114 — not embedded in this deck.
MCQ exam: guess vs leave blank with negative marking. Simulate strategies over many papers; find the break-even knowledge level.
**Input:** 40 questions, 4 options each; +1 correct, -0.25 wrong; guess-all vs leave-blank**Output:** guess-all EV = (1/4)(+1) + (3/4)(-0.25) = +0.0625 per question — the marking was calibrated so blind guessing is near-neutral; with partial knowledge (one option eliminated) EV = +0.1667 per question, so guessing wins once you can rule something outSolve 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-115 — not embedded in this deck.
Estimate pi by dropping needles (or its discrete cousin, random points in a square). Simulation as an estimator; error shrinking like 1/sqrt(n).
**Input:** unit square, random point (x, y); inside quarter circle if x^2+y^2 <= 1**Output:** pi ~ 4 x inside/total; 100k points -> ~3.14 ± 0.005; error ~ 1/sqrt(n)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-116 — not embedded in this deck.