Follow by Email

Sunday, March 14, 2010

The Fourth Annual Computer Competition (Part 1 of 4)

(Introduction and Part 1Part 2, Part 3, Part 4)

Introduction

During my junior and senior years at high school I participated in a county-wide computer programming competition.

The day before the first competition, my junior year, the president of the computer club challenged me to a quick on-paper coding competition to see who should go. I beat him handily, and he was kind enough to give me the spot. Charles was a brilliant guy who I'm sure did just fine without the competition on his resume.

Both years, the competition went like so: every student was allocated an observer-judge. The judge was responsible for resetting the programming environment, clearing code and data, watching the student during the test, and then, when the student was done, would test the program with a predetermined data set. Correct exact results meant the student earned one point. Any incorrect result meant zero points.

The junior year I tied for third place with four other kids, resulting in a sudden-death run-off. (I remember getting at least one question incorrect. Did I get two wrong? My ego is struggling with the possibility.) I'm positive that had I not paused to test my program during the run-off I would have taken third-place, and the TRS-80 would have been mine. Alas.

The senior year's competition was the day after my prom, and I chose not to attend the prom in order to get a good night's rest. (This is a lie; I didn't attend the prom for plenty of reasons, most of which was I didn't fit in. My girlfriend and I had dinner at Gasho of Japan instead.) I don't remember doing well enough to win or place.

Tonight, while going through some old boxes in the basement, I came across one of the competition packets. There's no year on the packet, so I can't tell for which competition it was. There are four questions, labeled two through five, meaning that one of the questions is missing.

I'll publish the four questions, each as its own blog post. I won't include sample answers, because mine were built and destroyed quicker than sand sculptures. Plus they were written in BASIC, and I love you, but not that much.

The first question, Question #2.

Question #2 Senior Division

Write a program that will ask for six 3-digit numbers (without signs) to be input one at a time. ANY 3-digit number is valid. (Examples: 123, 049, 899, etc...). If anything else is input (letters, etc.) the program MUST output the EXACT error message "PLEASE INPUT THREE DIGITS ONLY", and then request the number again. After SIX 3-digit numbers are properly input the program is to tally the digits according to their position and output a table listing how many times a particular number appears at each position (hundreds, tens and units place.) See the SAMPLE RUN for clarification.

NOTES:
1. Try to make your output table easy to read, but do not worry about all numbers lining up perfectly since various computers differ slightly in formatting. [The judge will be looking for accuracy of output, not formatting of output.]
2. To make your task a bit easier you may assume that the judges will NOT attempt to input any commas or quotation marks. Any other input, however (letters, numbers, +/-, etc.) is "fair game", so make sure to test your program thoroughly.

SAMPLE RUN
RUN
3-DIGIT NUMBER 1? 364
3-DIGIT NUMBER 2? XYZ
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 2? 446
3-DIGIT NUMBER 3? 780
3-DIGIT NUMBER 4? 8994
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 4? 507
3-DIGIT NUMBER 5? 5B7
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 5? 060
3-DIGIT NUMBER 6? 492


TALLY   HUND    TEN     UNIT
-----   ----    ---     ----
ZERO     1       1       2
ONE      0       0       0
TWO      0       0       1
THREE    1       0       0
FOUR     2       1       1
FIVE     1       0       0
SIX      0       2       1
SEVEN    1       0       1
EIGHT    0       1       0
NINE     0       1       0


No comments: