Bridge Crossing
Three people, Alice, Bob, and Pete, must cross a bridge at night. The bridge can hold at most
two people at a time, and the group has only one torch which must be carried on every crossing.
Someone must bring the torch back before the remaining people can cross.
Variables
The spec should contain three variables:
nearSide— the set of people currently on the near side of the bridge.farSide— the set of people currently on the far side of the bridge.torchOnNearSide— a boolean indicating whether the torch is on the near side.
Initial State
Initially all three people are on the near side, the far side is empty, and the torch is on the near side.
Transitions
- If the torch is on the near side and the near side is not empty, one or two people can cross from the near side to the far side. The torch moves with them.
- If the torch is on the far side and the far side is not empty, exactly one person returns from the far side to the near side. The torch moves with them.