The State Machine
Of course we can model this puzzle as a state machine. We have states (1 through 5) and 8 transitions (a through h). Again, this is an undirected graph:
Accordingly, the transition table looks like this:
| State | Message | State | ||
|---|---|---|---|---|
| 1 | ⟵ | a | ⟶ | 2 |
| 2 | ⟵ | b | ⟶ | 3 |
| 3 | ⟵ | c | ⟶ | 5 |
| 5 | ⟵ | d | ⟶ | 4 |
| 4 | ⟵ | e | ⟶ | 1 |
| 1 | ⟵ | f | ⟶ | 3 |
| 2 | ⟵ | g | ⟶ | 4 |
| 3 | ⟵ | h | ⟶ | 4 |