Aug 92 Challenge
Volume Number: | | 8
|
Issue Number: | | 4
|
Column Tag: | | Programmers' Challenge
|
Programmers' Challenge
By Mike Scanlin, MacTutor Regular Contributing Author
Welcome to Programmers Challenge of the Month wherein each month you will find an interesting programming problem and get the chance to win an insanely great prize, not to mention get your name in print in this prestigious magazine to show all your wannabe friends.
The Rules
Heres how it works: Each month there will be a different programming challenge presented here. First, you must write some code that solves the challenge. Second, you must optimize your code (a lot). Then, submit your solution to MacTutor. A winner will be chosen based on code correctness, speed, size and elegance (in that order of importance) as well as the postmark of the answer. In the event of multiple equally desirable solutions, one winner will be chosen at random (with honorable mention, but no prize, given to the runners up). The prize for the best solution each month is $50 and a limited edition I won the MacTutor Programming Challenge T-shirt (not to be found in stores).1
In order to make fair comparisons between solutions, all solutions must be in ANSI compatible C. When timing routines, the latest version of THINK C will be used (with ANSI Settings plus Honor register first and Use Global Optimizer turned on) so beware if you optimize for a different C compiler.
The solution and winners for a months Programmers Challenge will be published in the issue two months later (i.e., the solutions for this month will appear in the October issue). The deadline for submitting a solution is a postmark of September 10, 1992.
All solutions should be marked Attn: Programmers Challenge Solution and sent to Xplain Corporation via snail mail or e-mail. If you send via snail mail, please include a disk with the solution and all related files (including contact information). See the staff page at the front of the magazine for information on How to Contact Xplain Corporation.
MacTutor reserves the right to publish any solution entered in the Programming Challenge of the Month and all entries are the property of MacTutor upon submission. The submission falls under all the same conventions of an article submission.
Also, if you have any great ideas for future programming challenges send them in, too.
1 The prize is subject to change in the event of production problems.
The Scene
Contestant #1
I can write that routine in 200 bytes and 700 cycles.
Contestant #2:
I can do it in 180 bytes.
Contestant #1
150 bytes and 500 cycles.
Contestant #2:
<silence>
Announcer:
Contestant #1, write that routine!
This months Challenge
You have a piece of wood with a 13 x 13 array of holes drilled into it, 1 inch apart (169 holes total, covering one square foot). Into these holes you place 3 to 100 pegs. You then take a rubber band and surround all the pegs and let go. What pegs does the rubber band touch and what is the area inside the rubber band?
The input to your function is a short, numPegs, a pointer to an array of Points, pegsPtr. The output is a short, numEdgePegs, an array of Points, edgePegs (which can be in any order) and a Fixed, area. Here is the prototype:
void BandedPegs(numPegs, pegsPtr, numEdgePegsPtr, edgePegsPtr, areaPtr)
short numPegs;
Point *pegsPtr;
short *numEdgePegsPtr;
Point *edgePegsPtr;
Fixed *areaPtr;
Example:
Input:
numPegs = 7
*pegsPtr = {6,6}, {8,5}, {6,7}, {5,6}, {7,7}, {6,5}, {6,9}
Output:
*numEdgePegsPtr = 5
*edgePegsPtr = {8,5}, {5,6}, {7,7}, {6,5}, {6,9}
*areaPtr = 6.0
Good luck! Ready, set, go!