Tesla interview question

How to implement a state machine.