How to solve this problem. I have reckoned that I need to take as optimization problem finding minimum value for waiting time. Any suggestions?
Calvin has to cross several signals when he walks from his home to school. Each of these signals operate independently. They alternate every 80 seconds between green light and red light.At each signal, there is a counter display that tells him how long it will be before the current signal light changes. Calvin has a magic wand which lets him turn a signal from red to green instantaneously. However, this wand comes with limited battery life, so he can use it only for a specified number of times.
a. If the total number of signals is 2 and Calvin can use his magic wand only once, then what is the expected waiting time at the signals when Calvin optimally walks from his home to school?
b. What if the number of signals is 3 and Calvin can use his magic wand only once?

Solution to (a) and (b) and the general case can be found in this paper, together with code and a simulation to verify the results. I think it is instructive for those new to statistical modeling.
a. Expected trip time is 8.75 sec. Optimally, wand should be used on red light if the counter is above 20 sec.
b. Expected trip time is 21.32 sec. Optimal wand usage at first light is if the counter is above 31.25 sec, and 20 at the second if there is a charge left.
c. Consult the paper for the recursive 10-line code that solves the general case. For example, if there are 4 lights and Calvin has 2 charges, then the expected trip time is 11.8 sec with the optimal wand usage.