How does a little algebra collapse three nested loops into one — turning a billion brute-force checks into a thousand?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Three nested for loops, each running over range(3) (the values 0, 1, 2), sweep through every combination of three numbers. Write those loops and add 1 to count once for each combination they visit.
A word problem encoded as Boolean conditions
Write the ticket problem's three conditions a + b + c == 10, b == a - 2 and c == 2 * a, and the values of a, b and c that satisfy all three.
Three nested for loops over all combinations
Write the triple loop over a, b and c that tests every combination, and record that with a total of 1000 tickets each of the three ranges runs to 1000.
Algebra plus a single loop
Rewrite the search as one loop over Alyssa's ticket count, computing Ben's and Cindy's counts from the two relations and checking their sum against the required total.