Create a flow graph. Try to pass through the system manually first Here is our flow graph. I do not pretend on absolute perfection, somebody of you definitely will make this more effective and optimized, this is just an example. This algorithm has two advantages. First, at any situation it will show you what you have to do. Second, it is adopted to make a program.