# DELETIONS EASY Solution

This game is from the book On Numbers and Games by John Conway (Academic Press, 1976) PROBLEM: Given a sequence of digits, modify the sequence by: 1. Deleting all zeros, if any, and all the digits to their left 2. Changing a digit to a value less than that digit (by some set of rules). No negatives allowed. In a real game the player who removes the last digit loses

For this program, given the sequence, remove all the zeros, if any, and all the digits to their left. Then find the largest remaining digit and if it is even subtract 2 from it or if it is odd subtract 1 from it. If two or more digits become tied as the largest digit, use the rightmost digit as the largest. Repeat the application of the rules to the sequence. How shown below: many moves were required to delete the sequence?

Two examples are

MOVES 358 0254 83 0751 254 2 44 242 751 651 451 44 1 4 21 221 201 4 220

EMPTY 10 INPUT:

There will be 5 lines of input. Each input will consist of a sequence of positive integers. The first integer will tell how many integers are in the sequence that will follow. OUTPUT: Print the number of moves required to delete all the digits

SAMPLE INPUT SAMPLE OUTPUT 1. 7, 3, 5, 8, 0, 2, 5, 4 2. 6,8,3, 0, 7, 5,'1 3. 5, 5, 0, 6, 0,4 1. 6 2. 10

For this program, given the sequence, remove all the zeros, if any, and all the digits to their left. Then find the largest remaining digit and if it is even subtract 2 from it or if it is odd subtract 1 from it. If two or more digits become tied as the largest digit, use the rightmost digit as the largest. Repeat the application of the rules to the sequence. How shown below: many moves were required to delete the sequence?

Two examples are

MOVES 358 0254 83 0751 254 2 44 242 751 651 451 44 1 4 21 221 201 4 220

EMPTY 10 INPUT:

There will be 5 lines of input. Each input will consist of a sequence of positive integers. The first integer will tell how many integers are in the sequence that will follow. OUTPUT: Print the number of moves required to delete all the digits

SAMPLE INPUT SAMPLE OUTPUT 1. 7, 3, 5, 8, 0, 2, 5, 4 2. 6,8,3, 0, 7, 5,'1 3. 5, 5, 0, 6, 0,4 1. 6 2. 10

You'll get 1 file (64.1KB)