# 1996 LSU High School Programming Contest Veteran's Problems

## Advanced #1: The Baffle Game

The Baffle Game is played on a 2-dimensional 10 by 10 grid with the numbers 0 through 39 around the sides (see illustration.) There are obstructions, called "baffles," placed in the box. The object of the game is to determine, given the placement and direction of the baffles, where a laser beam origi- nating at one of the locations 0-39 will exit the box. A beam not encountering a baffle will exit directly opposite where it entered. A beam encountering a baffle will be deflected at right angles, either right or left, depending on the direction of the baffle.

For example, given the grid above, a beam shot from 7 comes out at 22. A beam shot from 1 is deflected once and exits at 37. A beam shot from 27 exits at 2 without being deflected. A beam shot from 5 comes out at 17 after three de- flections. A beam shot from 12 is deflected once, exiting at 24. A beam shot from 20 exits at 30.

Write a program which first reads placement information for an unknown number (no more than 10) of baffles. The information for each baffle will be one line of input, entered interactively, in the format:

```X Y dir
```

where:

• X is an integer between 0 and 9
• Y is an integer between 10 and 19
• dir is either an 'R' or an 'L'

X, Y, and dir will be separated by at least one blank, maybe more. For example, the following data places the baffles in the locations indicated by the illustration above:

```5  12  L
9  19  R
3  10  R
1  12  L
1  17  R
-1
```

Note that the end of the baffle placement data will be marked by a line con- taining a single negative integer. After reading the baffle placement data, the program will prompt for, one at a time, integers representing the origi- nation points of shots. Your program should read and process shots until a negative integer is entered. For each shot, echo-print its origination point and then print its exit point. For example:

```LASER SHOT FROM  7 EXITS AT 22.
LASER SHOT FROM 12 EXITS AT 24.
```

You are guaranteed that all data is valid and that all shots will exit the box.

Sample run:

```ENTER BAFFLE PLACEMENT DATA:
5  12  L
9  19  R
3  10  R
1  12  L
1  17  R
-1
ENTER ORIGINATION POINT: 7
LASER SHOT FROM  7 EXITS AT 22.
ENTER ORIGINATION POINT: 12
LASER SHOT FROM 12 EXITS AT 24.
ENTER ORIGINATION POINT: 1
LASER SHOT FROM  1 EXITS AT 37.
ENTER ORIGINATION POINT: 27
LASER SHOT FROM 27 EXITS AT 2.
ENTER ORIGINATION POINT: -99
GOODBYE.
```

## Advanced #2: Moirre Triangles

This problem involves drawing what may be loosely termed a Moirre triangle, where the word "Moirre" refers to the type of pattern we will generate inside of the triangle.

Input to the program is interactive. The initial prompt is 'INPUT A TRIANGLE (Y/N)?'. If Y is entered, prompt for data with 'ENTER DATA:'. Once the triangle has been printed, ask if the user wants to print another with the prompt 'INPUT ANOTHER TRIANGLE (Y/N)?'.

Each line of data entered by the user will consist of four positive integers followed by three characters. There will be exactly one blank between all input values. The program should draw one isosceles triangle per input line. Two blank lines should be left between the last line of output for a triangle and the subsequent prompt.

The first integer will be the width of the page (1 (= pagewidth (= 80). The second integer will be the height of the triangle (guaranteed small enough so that its base may be printed in pagewidth or less characters). The triangle drawing must be centered with its peak in the middle of the page. If the triangle may not be exactly centered, there should be one more empty column to the left of the base of the triangle than to the right of it.

The third and fourth integers will be, respectively, the number of consecutive background characters and the number of consecutive foreground characters to use in the drawing (see sample output for clarification). The three characters will be the symbol used to draw the edges of the triangle, the background char- acter, and the foreground character, in that order.

Before printing the triangle, echo-print the data in the form shown in the sample run. Below the triangle should be displayed a scale, of the form shown below, equal in length to the pagewidth.

Sample run: (note that the peak of the triangle is in column 40, giving 20 empty columns to the left of the base and 19 to the right of it):

```INPUT A TRIANGLE (Y/N)? Y
ENTER DATA:
78 20 3 8 * . o

PAGE WIDTH    = 78
TRIANGLE HT   = 20
NUM BACK CHRS =  3
NUM FORE CHRS =  8
EDGESYMBOL    =  *
BACKGROUND    =  .
FOREGROUND    =  o
*
*o*
*ooo*
*oooo.*
*..ooooo*
*ooo...ooo*
*ooooo...ooo*
*ooooo...ooooo*
*ooo...oooooooo.*
*..oooooooo...oooo*
*oooo...oooooooo...o*
*ooooooo...oooooooo...*
*oooooooo...oooooooo...o*
*ooooooo...oooooooo...oooo*
*oooo...oooooooo...oooooooo.*
*..oooooooo...oooooooo...ooooo*
*ooo...oooooooo...oooooooo...ooo*
*ooooo...oooooooo...oooooooo...ooo*
*ooooo...oooooooo...oooooooo...ooooo*
***************************************
123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678

INPUT ANOTHER TRIANGLE (Y/N)? N
GOODBYE.
```

## Advanced #3: Spiral Sentences

Write a program which will receive as input two data lines. The first line of input will be a string of characters. The second line of input will be a posi- tive integer, N. The program should print out the input string repeatedly in the form of a square spiral, until a total of N characters have been printed.

All blanks in the input string should be replaced with the character '+' to give the arms of the spiral a more connected appearance. Put the character '*' between successive appearances of the string. The input string will be no more than 35 characters; N will be no more than 200. The arms of the spiral should be separated by one blank column/row (see illustration). The number of blank lines between the output line 'SPIRAL SENTENCE:' and the topmost arm of the spiral does not matter; the number of blank columns between the left edge of the screen and the leftmost arm of the spiral does not matter. The position of the centermost character of the spiral on the page does not matter.

Sample run:

```ENTER STRING:
OLD KING COLE WAS A MERRY OLD SOUL

ENTER N:
100

SPIRAL SENTENCE:

+GNIK+DLO*LUO
C           S
O LO*LUOS+D +
L D       L D
E + OC+GN O L
+ K L   I + O
W I E O K Y +
A N + LD+ R Y
S G W     R R
+ + AS+A+ME R
A C         E
+ OLE+WAS+A+M
M
ERRY+OLD+
```

## Advanced #4: The Pharoah's Pyramid

Pyramids are built by layering cubic blocks 1 unit on a side in the following manner:

The top layer contains 1 block, the next layer down contains 4 blocks (2 by 2) the next layer down contains 9 blocks (3 by 3) etc... Each layer in the complete pyramid will be a perfect square.

The work crew has collected N blocks at the work site. The Pharaoh is in a hurry and wants to know how many layers he can have in his pyramid if they stop collecting blocks now and use only what they have already gathered (note that there may be some blocks left over).

The Pharaoh wants his pyramid to have an inner chamber, also pyramid shaped, built under the same constraints as exist for the pyramid itself, left hollow in the center of the pyramid. This will free up extra blocks such that it might be possible to build a larger pyramid than if the pyramid were solid.

In order to house such an inner chamber, the outer pyramid must be at least 2 layers taller than the inner chamber, so that the top-center 1x1x1 hollow space that is the top level of the inner chamber will fit into the space normally taken by the center block of the third layer from the top of the pyramid.

Note: The pyramid and the inner chamber may share the bottom layer and still be legal. In other words, the inner chamber is considered to be "contained" by the pyramid even if they both start "at ground level" so to speak. Example: A 3 level high pyramid with a 1 level high chamber would be legal.

Write a program that accepts as input the number of blocks available. Output should be a table listing all possible combinations of pyramid height and inner chamber height that could actually be constructed under the construction guidelines given above. The program should prompt repeatedly for a number of blocks, printing a table for each input number. When a negative value is entered for the number of blocks available, the program should terminate and print " GOODBYE.".

Sample run:

```ENTER NUMBER OF BLOCKS AVAILABLE: 13
LEGAL COMBINATIONS OF PYRAMID AND INNER CHAMBER HEIGHT:
Pyramid Height:     3  Inner Chamber Height:     1
Pyramid Height:     2  Inner Chamber Height:     0
Pyramid Height:     1  Inner Chamber Height:     0
Pyramid Height:     0  Inner Chamber Height:     0

ENTER NUMBER OF BLOCKS AVAILABLE: 42
LEGAL COMBINATIONS OF PYRAMID AND INNER CHAMBER HEIGHT:
Pyramid Height:     5  Inner Chamber Height:     3
Pyramid Height:     4  Inner Chamber Height:     0
Pyramid Height:     4  Inner Chamber Height:     1
Pyramid Height:     4  Inner Chamber Height:     2
Pyramid Height:     3  Inner Chamber Height:     0
Pyramid Height:     3  Inner Chamber Height:     1
Pyramid Height:     2  Inner Chamber Height:     0
Pyramid Height:     1  Inner Chamber Height:     0
Pyramid Height:     0  Inner Chamber Height:     0

ENTER NUMBER OF BLOCKS AVAILABLE: -1
GOODBYE.

Advanced #5:  Pig Latin

Write a program which will convert ordinary English into Pig Latin.  Input
will be five lines of English text.  Output will be the five lines translated
into Pig Latin.

The rules for converting English into Pig Latin are:

If a word begins with a vowel, add the syllable 'way' to the end of the
word.  Thus, "island" becomes "islandway"; "apple" becomes "appleway".
For this program, vowels are a, e, i, o, and u (not y).
If a word begins with one or more consecutive consonants, the consonants
are moved in the same order to the end of the word, and the syllable
'ay' is added after them.  Thus, "catch" becomes "atchcay"; "scratch"
becomes "atchscray"; "don't" becomes "on'tday"; "flag" becomes "agflay".

All punctuation should be retained in its proper relative position in the Pig
Latin text.  The division of the input text into lines should be duplicated in
the Pig Latin text.  If an English word is capitalized, its Pig Latin version
should be, too.  You may assume that the Pig Latin version of any given line
will be 80 characters long or less and that the input text will not contain
any digits.

Sample run:

ENTER FIVE LINES OF ENGLISH TEXT:
It had a star atop which said "Mom's Rooming House
and Dormitory."  It looked like a private,
one-story residence, a shine stand on its left,
a liquor store on its right.  Lots of street
corner loiterers.

HERE IS THE PIG LATIN VERSION:
Itway adhay away arstay atopway ichwhay aidsay "Om'smay Oomingray Ousehay
andway Ormitoryday."  Itway ookedlay ikelay away ivatepray,
one-storyway esidenceway, away ineshay andstay onway itsway eftlay,
away iquorlay orestay onway itsway ightray.  Otslay ofway eetstray
ornercay oitererslay.

GOODBYE.

Advanced #6:  Clock Patience

You are to simulate playing one game of Clock-Patience, a popular card soli-
taire game.  The starting pre-shuffled deck of 52 cards is represented in
the input as follows:

thirteen cards per line of input
four consecutive lines of input represent one deck
each card is represented by its face name (suit is immaterial to the game)
where face names are A,2,3,4,5,6,7,8,9,T,J,Q,K
no blanks between face names on a line

Deal the cards, one at a time, "face down" in a clockwise fashion so they would
cover the numbers of a standard analog clock.  Begin the deal at one
o'clock and
proceed to twelve o'clock, then place one card in the center of the clock. Con-
tinue to deal, in this fashion, from the pre-shuffled deck until all 52 cards
are distributed "face down".

After all 52 cards are dealt, begin the game by drawing the top card from the
central pile.  Place this card "face up" under the pile that corresponds to its
face value on the clock, and use the top card of that pile as your next card.
For example, an ace is placed under the pile at the one o'clock position and
the next card is taken from the top of this pile.  A jack is placed under the
eleven o'clock pile, a queen under the twelve o'clock pile, and a king under
the center pile.  Whenever you place a card "face up" on the bottom of a pile
you must remove the top card of that pile and use it as your next card.  The
game continues in this way until you turn up the fourth king.

A pile is said to be "completed" when all four of a kind appear in the pile.
When the game ends (i.e. when the king pile is completed), output a line con-
taining the face names of the completed piles, in the order in which they were
completed (first pile completed is output first, second pile completed is
output
second, etc.)  Place nothing extra on the line.  Do not place any spaces
between
the face names on the output line.  Note that the output line should always end
with a K since the completion of the king pile ends the game.

Sample run #1:

ENTER SHUFFLED DECK, 4 LINES OF 13 CARDS PER LINE:
J729QT86K8335
A4AQ958T723JK
952446T4K78Q6
AJ3652KJT9AQ7

COMPLETED PILES:
5QAJ349K
GOODBYE.

Sample run #2:

ENTER SHUFFLED DECK, 4 LINES OF 13 CARDS PER LINE:
67T47K943534A
2Q9423K5QJ787
K662JTJK5TT89
8J68Q259AQA3A

COMPLETED PILES:
JQ82A6K
GOODBYE.

```