This is my answer to one of the exercises in Chris Pine's book Learn to Program.