Problem #7


Competitive Spelling


You are to write an interactive game where two contestants, a witch and a wizard, complete to capture a primal spell. To do this, the witch and wizard must maneuver on the “integer number line of magic”. The wizard starts out at position -200, the witch at position +200, and the primal spell is at position 0. The first to reach or pass position 0 captures the spell and the game is over.

In one turn cycle of the game, a random unit of magical energy (an integer somewhere between 25 and 100 inclusive) is produced by the game. The contestant witch and wizard each make a guess as to what that unit of magical energy is. The one closest to the actual number is awarded the unit of energy. The two users are not allowed to input the same number. If the witch captures the magical energy, that unit is subtracted from her position. If the wizard captures the magical energy, that unit is added to his position.

The position of the wizard and the witch are output at the beginning of each turn cycle. The game halts when the wizard wins by reaching the position 0 or moves into the positive side of the number line. The game halts when the witch wins by reaching the position 0 or moves into the negative side of the number line.

At the end of the game, the final positions of the contestants and the winner are announced.