a. Let's look at what happens with the state of one light when executing a move. Each move either changes or preserves the state of the light. Thus the final state of some light only depends on the number of moves made that change the state of that light, and not on the order of the moves made. Therefore the final state of all the lights also does not depend on the order of the moves made.
b. This is possible for exactly those n which are divisible by 3.
Suppose first that n is divisible by 3 and let's prove that in this case we can indeed reach the desired state. Let Pi be the move where we change the states of the i-th, (i+1)-st, and (i+2)-nd light in the line. Since n is divisible by 3 and each move changes the state of 3 lights we can change the states of all the lights in the row by making 3n moves P1,P4,P7,…,Pn−2, and thus reach the desired state.
Now let's prove that we can reach the desired state only if n is divisible by 3. We already know that the order of the moves is not important, so we may assume that we make moves Pi in the increasing order determined by i. If we make the move Pi twice the state of the light is preserved. Therefore we may also assume that we make each move Pi at most one time. This basically means that we only need to decide for each move Pi if we make it or not. At the end each odd light must be turned off and each even light turned on. Since we need to change the state of the 1st light, which can only be done by the move P1, we must make the move P1. After this move the first three lights are already in the desired state. Since P2 is the only other move that changes the state of the 2nd light we must not make this move. Among the moves P3,P4,P5,… the move P3 is the only one that changes the state of the 3rd light, thus we must also not make this move. Now we are at the move P4 and we make a similar argument. We need to change the state of the 4th light, hence we must make the move P4. After this move the 4th, 5th, and 6th light are in the desired state, so we must not make the move P5 nor the move P6. We continue in a similar matter, we make move P7 and don't make moves P8 and P9, and so on. This means that we must necessarily make the sequence of moves P1,P4,P7,…. For this sequence to change the state of all the lights in the line, n must be divisible by 3. Indeed, if n has remainder 1 when divided by 3, then we will not change the state of the last light since the move Pn is not allowed as it only changes the state of one light. Similarly, if n has remainder 2 when divided by 3, then we will not change the state of the last two lights since the moves Pn−1 and Pn are not allowed.