What goes in the blank?
# ways to climb n steps, 1 or 2 at a time
def ways(n):
a, b = 1, 1
for _ in range(n):
a, b = b, a ____ b
return a
Answer: +
ways(n) = ways(n-1) + ways(n-2), the Fibonacci recurrence kept in two rolling variables.
Play Problem Solving ▸