The rope bridge problem

This puzzle appears in The Little Book of Semaphores as the Baboon crossing problem, section 6.3. Downey notes that it is adapted from Tanenbaum's Operating Systems: Design and Implementation, so you're getting it third-hand here. The problem description is thus:

"There is a deep canyon somewhere in Kruger National Park, South Africa, and a single rope that spans the canyon. Baboons can cross the canyon by swinging hand-over-hand on the rope, but if two baboons going in opposite directions meet in the middle, they will fight and drop to their deaths. Furthermore, the rope is only strong enough to hold 5 baboons. If there are more baboons on the rope at the same time, it will break.Assuming that we can teach the baboons ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.