added solution #2, proof of termination