lights out algorithm