Challenge Level

Can you prove that the algorithm will always work?

NOTES AND BACKGROUND

When computers do their various jobs they follow very clearly described procedures. These are series of instructions where the next step at each stage is 100% clearly described: no choices or decisions need to be made; the computer is told exactly what to do. The art of the computer programmer is to work out how to break down a task into such a series of steps so that the computer knows exactly how to perform that task.

The procedure in this question is an example of such a breakdown. The computer user would input the two numbers X and Y and the computer would then run through the procedure until it terminates.

Thinking in this procedural way is an important skill to develop for anyone wishing to learn how to program a computer (and perhaps to earn a great deal of money!).