Senior Division 1981
1. PARKSIDE'S  TRIANGLE
PARKSIDE'S  TRIANGLE is generated from two numbers--the size 
and the seed. The size determines how many rows are in the triangle 
and the seed determines the first number in the triangle. Here are two 
examples:

SIZE 6,SEED 1   SIZE 5, SEED 3

 1 2 4 7 2 7       3 4 6 9 4
   3 5 8 3 8         5 7 1 5 
     6 9 4 9           8 2 6 
       1 5 1             3 7
         6 2               8
           3

Analyze the above examples, discover the rule, and write a program 
that will generate PARKSIDE'S  TRIANGLE given any size N 
(N_20) and any seed S (1_S_9).  Test your program by generating 
PARKSIDE'S TRIANGLE for N=6, S=1 and N=7, S=9.

Sample Run

PARKSIDE'S  TRIANGLE
SIZE,SEED ? 7,9

  9 1 3 6 1 6 3
    2 4 7 2 7 4
      5 8 3 8 5
        9 4 9 6
          5 1 7
            2 8
              9

2. DIGITAL PRODUCT ROOT
The digital product of a positive integer , N,  is defined to be the 
product of its nonzero decimal digits. For example, the digital 
product of the integer 99 is 9x9 or 81.  The digital product of 81 is 
8x1 or 8. The DIGITAL PRODUCT ROOT of a positive integer  N is 
obtained by repeatedly taking digital products until a single digit is 
obtained.  In the example above, 8 is the DIGITAL PRODUCT 
ROOT of 99. 

Write a program which will accept a positive number up to 70 digits 
long as an input and print out each step in the computation of the 
DIGITAL PRODUCT ROOT. 


Test your program with the inputs 123456789, 9999999999.

Sample Run

ENTER A NUMBER 123456789
123456789
362880
2304
24
8
THE DIGITAL PRODUCT ROOT IS 8

3. BUG WALK
A bug begins at home (X) and goes for a random walk on a strip of 
2N+1 long:

   -N ...-3  -2  -1   X   1  2  3 .....   N
                        HOME
 
It moves to the right or the left one number at a time in a random 
fashion.  It moves to the right with probability P (0_P_1)  and it 
moves to the left with probability   1-P.  When the bug reaches  either 
end of the range, its next move is always toward home and then it 
continues the random walk. After the bug has returned home for the 
tenth time it stops. 

Write a program that simulates the bug's random walk for inputs N 
and P and prints out a list of all the numbers the bug has visited, and 
the number of times he has been there.  Print out the list in order of 
frequency, giving the most frequently visited number first.  Run the 
program N=5, P=1/2 and N=6, P=2/3.

Sample Run

ENTER N = 5
ENTER P = .5

NUMBER     OCCURRENCES
======     ===========
-2          11
-4          10
-1          10
 0          10
-5          8
-3          8
 1          6
 2          1

4. WORD COUNT
Consider  a paragraph containing several lines of text information.  
Write a program to print a word length frequency table. This table 
should list the word length, frequency of occurrence, and percentage, 
in three columns, in order of highest frequency first.

For purposes of this problem, a word consists only of alphabetic 
characters (A through Z).  Different words (such as "FOR" and 
"THE") having the same length are counted together in determining 
the word length frequency.  Do  not list word lengths that do not 
occur in the paragraph. 

Test your program with the first paragraph of this problem  - 
"CONSIDER...FIRST."

Sample Run

LENGTH   FREQ     %
======   ====     ======
 5        8       18.6
 2        7       16.27
 4        5       11.62
 3        4       9.3
 7        4       9.3
 9        4       9.3
 1        3       6.97
 6        3       6.97
 10       3       6,97
 11       3       2.32
 8        1       2.32

TOTAL = 43

5. SHUTTLE PUZZLE
The SHUTTLE PUZZLE of size 3 consists of three white marbles, 
three black marbles, and a strip of wood with 7 holes.  The marbles of 
the same color are placed in the holes at the opposite ends of the strip 
leaving the center hole empty  (X is empty space).

----------------------------------
1    1    1    X    0    0    0
----------------------------------
	       INITIAL  STATE  

The object of the puzzle is to completely reverse the marbles on the 
strip and end up with:



----------------------------------
0    0    0    X    1    1    1
----------------------------------
	         GOAL STATE

There are only two types of moves you can use.  You may move 1 
marble 1 space (into an empty hole) or jump 1 marble over 1 marble 
of the opposite color (into an empty hole).  You may not back up and 
you may not jump over 2 marbles.

A Shuttle Puzzle of size N consists of N black marbles and N white 
marbles and 2N+1 holes.

Write a program that will solve the SHUTTLE PUZZLE for any size 
N(_10) and display the board after each move.  Use 0's to represent 
white marbles and 1's to represent black marbles and a blank to 
represent the empty hole.  Thus 111 000 is the initial state and 000 
111 is the goal state in a SHUTTLE PUZZLE of size 3. Test your 
program for N=3 and N=4. 

Hint:  First figure out how to solve the puzzle.  Next, observe the 
movement of the empty space.  Finally find the rules that govern the 
movement of the hole to the left and right and program the computer 
to carry them out.

Sample Run

N =  3

111 000
1110 00
11 0100
1 10100
101 100
10101 0
101010 
1010 01
10 0101
 010101
0 10101
001 101
00101 1
0010 11
00 0111
000 111
	ICPSC 1981
	Senior Division Problems


