Turing’s World Ch8 Exercise2
|Exercise 2 (Lights out) Imagine that you have three light switches, numbered 1,2, and 3, controlling two lights in a hallway, one at the north end, the other at the south end. The way the switches work is as follows:
Design a one-way finite state machine that checks to see if both the lights are off. That is, it should accept a string of 1’s, 2’s, and 3’s if and only if the string represents a sequence of switch flips that results in both the lights being off (assuming they were off to start with). For example, it should accept the string 213 since this turns on both the lights and then turns off the north light and then the south light. By contrast, it should reject the string 23213 since this sequence of flips leaves the north light on.
|Current State||Symbol Read||Action||Next State|
State 0 is the accepting state.
State 0: all off
State 1: North light on
State 2: South light on
State 3: Both North and South lights on