Senior Division 1989

1. ARROWS
Write a program that will ask the user to make a choice between (U)p 
or (D)own and print out the corresponding arrow.  (Each arrow must 
be generated, not stored and printed.)

SAMPLE RUN

U
     *
    ***
   * * *
  *  *  *
 *   *   *
*    *    *
     *
     *
     *


D
     *
     *
     *
*    *    *
 *   *   *
  *  *  *
   * * *
    ***
     *



2. EVEN UP
If you toss a fair coin two times should you expect to get one head and 
one tail? If you toss the same coin ten times should you expect to get  
five heads and five tails?

To investigate this problem, write a program that will simulate the 
tossing of a fair coin N times (N must be even) and count the number 
heads minus tails. Repeat this experiment R times and summarize the 
results as shown below.

Test your program for N=4 , R=10 and N=10, R=20

SAMPLE RUN
Number of tosses (Even)? 4
Number of repetitions? 10

HTTT	-2
THHH	 2
HTTT	-2
THTT	-2
TTTT	-4
TTHH	 0
HTTH	 0
HTTT	-2
TTHH	 0
HHHH	 4
Heads-Tails Frequency
-4		   1
-2		   4
 0 		   3
 2		   1
 4		   1


3. SECRET CODE
You have just found the secret instructions on how to encode a 
message. 

"Calculate the message length and round up to the nearest multiple of 
5.  Write out the message in rows of 5 characters each until the 
message is complete. Send the message a column at a time from left to 
right."

For example, suppose the message is THIS IS A CODED MESSAGE
It is 23 character long so two spaces are added at the end to make the 
message 25 characters long. The rows of five characters are:
	
	1 2 3 4 5
	T H I S 
	I S   A
 	C O D E D
	  M E S S 
	A G E 

The characters are sent one column at a time from left to right
TIC.AHSOMGI.DEESAES...DS
(a period indicates a space)

Write a program that will encode or decode any message using the 
secret instructions.

Test your program by encoding the message:
MEET.ME.IN.THE.PARK.TONIGHT. AT.SEVEN

and decoding the message:
TE.AAECHCMGSNOEREE..D.ES.
BDESTSHEED

SAMPLE RUN

(E)ncode or (D)ecode ? D

Enter the message:
? TIC.AHSOMGI.DEESAES...DS

Decoded it reads:
THIS.IS.A.CODED.MESSAGE.


4. DICTIONARY ORDER
The  number 79 becomes "seven nine" when translated digit by digit 
into a string of words. Likewise, 80 becomes "eight  zero." When 
sorted as numbers, 79 comes before 80. But as a string of words "eight  
zero" comes before "seven nine" in the dictionary.

Write a program that asks the user to specify two whole numbers M,N 
between 1 and 99 and then print out the numbers between M and N in 
dictionary order. Arrange the numbers in rows of length 10. 

Test your program for M,N = 7,20 and 27,59

SAMPLE RUN
Enter M,N between 1 and 99? 7,20

8  9  18 15 14 19 11 17 16 13
12 10 7  20

5. ZERO SUM
Consider the sequence of digits from 1 through N (where N<=9)  in 
increasing order

	 1     2     3      4       5               N   

and insert either a 
	(+) for addition or a 
	(-) for subtraction or a 
	( ) a blank to run the digits together.   
Now sum the result and see if you get zero. 

Write a program that will find all sequences of length N that produce a 
ZERO SUM. 

 Test your program for N=7 and N=8.

SAMPLE RUN 

INPUT "ENTER A VALUE FOR N";7
THE ZERO SUMS ARE:
1 + 2 - 3 + 4 - 5 - 6 + 7 = 0
1 + 2 - 3 - 4 + 5 + 6 - 7 = 0
1 - 2 + 3 + 4 - 5 + 6 + 7 = 0
1 - 2 - 3 - 4 - 5 + 6 + 7 = 0
1 - 23 + 4 + 5 + 6 + 7 = 0
1 - 23 - 45 + 67 = 0
ICPSC 1989
Senior Open Problems

{PAGE}


