Solutions to the last exercise
Using a variable...
Cleaned up version:
Using only states (and fancy features)
First a fairly naive approach:
Then we try to make it orthogonal. First, an event-driven design came to mind.
It's probably nicer to clean this up and only depend one way: