Predict the output
What does this print?
chapters = [3, 6, 7, 11]
def hours_at(pace: int) -> int:
return sum(-(-c // pace) for c in chapters)
print([hours_at(p) for p in (3, 4, 6, 11)])Choose an answer, then open Show answer below to check it.
Show answer
Answer: A [10, 8, 6, 4]
Right: faster paces need fewer hours, never more.
Hours fall as pace rises, so the first pace that fits the limit can be found by halving.
Why not the others?
- B [9, 7, 5, 4]. Ceiling division rounds each chapter up separately.
- C [10, 8, 6, 3]. At pace 11 every chapter still takes at least one hour.