Senior Division 1983
1.  FREE LUNCH
Mac Duffy's is offering a FREE LUNCH to anyone who buys the 
proper combination of hamburgers, french fries, and soft drinks.

Here are the rules:
1. The menu consists of three items:
Hamburgers . . . . . $1.13
French Fries . . . . . $  .52
Soft Drinks . . . . .  $  .44

2.You must buy at least one hamburger.
3. You can buy at most three of each item.
4. If L is the subtotal for the lunch, then the sales tax is equal to .04xL.
5. The final bill equals the subtotal of the food plus the tax rounded off 
to the nearest penny (.01).  For example:
           
            $2.874= $2.87 and $2.875=$2.88.

6. If the total number of pennies in the final Bill (Bill*100) can be 
divided evenly  (with no remainder) by the prime numbers 2,3 and 5, 
then the lunch is free.

Write a program that will finds all orders that get a FREE LUNCH at 
Mac Duffy's.  Print out a report for each one as follows:

Sample Run

FREE LUNCH ORDER AT MAC DUFFY'S

ITEM    	COST  NUMBER
HAMBURGERS .....$1.13     2
FRENCH FRIES....$ .52     2
SOFT DRINKS.....$ .44     3

SUBTOTAL        $4.62
SALES TAX       $ .18
BILL            $4.80     
DIVISIBLE BY 2, 3, & 5 YOU WIN ! 



2. DE BUG
The process of debugging a computer program can be simulated by the 
following model:
1.  The probability that a program is bug-free on the first run is P 
where (0_ P _ 1).  2.  The probability that it is bug-free on the second 
run is increased by 1/2 of the probability that it failed on the previous 
try - an increase of (1-P)/2.
3.  If P is the probability that it runs bug-free on the N-1st try, then P + 
(1-P)/2 is the probability that it runs correctly on the Nth try.  A 
program is run until it is finally debugged.

Write a program that uses this model to simulate the debugging of 100 
programs.   Print a report of the results of your experiment as shown in 
the sample run. A typical report should look like the sample run  but 
every run will be slightly different.
 
Test your program for P=.3 and .5.
                          
Sample Run
ENTER PROBABILITY THAT A PROGRAM IS BUG FREE ON 
THE FIRST TRY: .3

DE BUG SIMULATION (P = .3)

N TRIALS     NUMBER OF PROGRAMS 		   DEBUGGED 
IN N TRIALS
1                   30
2                   49
3                   15
4                    6
AVERAGE # OF TRIALS TO DEBUG A PROGRAM IS 1.97


3. FACTORIAL POWER
The factorial of a whole number N is denoted by N! and defined as:

   N! = 1.2.3.4.5........N

For example,

  12!  = 1.2.3.4.5.6.7.8.9.10.11.12
         = 479001600

In the computation of 12!, the digit 6 is the right most non-zero digit 
followed by two zeros to the right.

Write a program that will compute the right-most non-zero digit in the 
decimal expansion of N! and find the number of zeros to the right of 
it. 

Test your program for N = 52, and 105.

Sample Run
ENTER A WHOLE NUMBER:   52

THE RIGHT-MOST NON-ZERO DIGIT OF 52! IS 4 AND IT IS 
FOLLOWED BY 12 ZEROS.




4. ALPHABETICALLY SPEAKING
Write a program that asks the user for a line of text and reorders the 
letters within each word in alphabetical order.

For example, the line:
THE PRICE OF BREAD IS $1.25 PER POUND.

would be converted to the line:
EHT CEIPR FO ABDER IS $1.25 EPR DNOPU.

Only letters from A to Z are ordered. All other characters must remain 
fixed in the same position as in the original word.

Test you program with the line above and the line:
THE LICENSE PLATE READ G76-ZA3.


Sample Run
ENTER A LINE OF TEXT:
THE PRICE OF BREAD IS $1.25 PER POUND.

OUTPUT:
EHT CEIPR FO ABDER IS $1.25 EPR DNOPU.



5. ALL LATIN SQUARES
A square arrangement of numbers

	1  2  3  4  5
	2  1  4  5  3
	3  4  5  1  2
	4  5  2  3  1
	5  3  1  2  4

is a 5 x 5 Latin Square because each whole number from 1 to 5 
appears once and only once in each row and column.

Write a program that will generate all NxN Latin Squares whose first 
row is:

1  2  3  4  5.......N

Your program should work for any N from 2 to 9.

Test your program for N=3 and 4.

Sample Run
ENTER A WHOLE NUMBER (2-9): 3

ALL 3 x 3 LATIN SQUARES :

#1
1  2  3
2  3  1
3  1  2


#2
1  2  3 
3  1  2
2  3  1



                                     ICPSC 1983
                             Senior Division Problems




