TweetFollow Us on Twitter

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

Here’s 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 month’s 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 month’s 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!

 
AAPL
$113.99
Apple Inc.
+1.98
MSFT
$47.88
Microsoft Corpora
-0.26
GOOG
$534.03
Google Inc.
+5.26

MacTech Search:
Community Search:

Software Updates via MacUpdate

MegaSeg 5.9.4 - Professional MP3 DJ appl...
MegaSeg is a complete solution for pro audio/video DJ mixing, radio automation, and music scheduling with rock-solid performance and an easy-to-use design. Mix with visual waveforms and Magic... Read more
Parallels Desktop 10.1.2 - Run Windows a...
Parallels Desktop is simply the world's bestselling, top-rated, and most trusted solution for running Windows applications on your Mac. With Parallels Desktop for Mac, you can seamlessly run both... Read more
GarageSale 6.9.1 - Create outstanding eB...
GarageSale is a slick, full-featured client application for the eBay online auction system. Create and manage your auctions with ease. With GarageSale, you can create, edit, track, and manage... Read more
Quicksilver 1.2.2 - Application launcher...
Quicksilver is a light, fast and free Mac application that gives you the power to control your Mac with keystrokes alone. Quicksilver allows you to find what you need quickly and easily, then act... Read more
Mac DVDRipper Pro 5.0.1 - Copy, backup,...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
ClamXav 2.7 - Free virus checker, based...
ClamXav is a free virus checker for OS X. It uses the tried, tested, and very popular ClamAV open source antivirus engine as a back end. I hope you like and use ClamXav a lot and that it helps keep... Read more
FoldersSynchronizer 4.2 - Synchronize or...
FoldersSynchronizer is a popular and useful utility that synchronizes and backs-up files, folders, disks and boot disks. On each session you can apply special options like Timers, Multiple Folders,... Read more
Waltr 1.0.6 - Drag-and-drop any media fi...
WALTR is designed to make it easy to upload and convert any music or video file to an iPad or iPhone format for native playback. It supports a huge variety of media file types, including MP3, MP4,... Read more
Tonality Pro 1.1.3 - Professional-grade...
Tonality Pro gives you the power to create stunning and dramatic black & white images. This is a complete monochrome image editor with more than 150 one-click style presets, totally unique... Read more
OS X NTP Security Update 1.0 - Addresses...
The OS X NTP Security Update addresses a critical security issue with the software that provides the Network Time Protocol service on OS X, and is recommended for all users. Version 1.0: Initial... Read more

Latest Forum Discussions

See All

Forget the Gloves – It’s a Cage Match in...
Forget the Gloves – It’s a Cage Match in Real Boxing’s Underground Update Posted by Jessica Fisher on December 23rd, 2014 [ permalink ] | Read more »
Who Wore it Best? Best of 2014
It’s the end of the year, so it’s time for some arbitrary internet awards! In this wrap-up episode of Who Wore it Best? we present our winners for the best, worst, and flat-out weirdest cloned games that graced the App Store in 2014. [ Who... | Read more »
Now You Can Explore Mayan Temples in Ass...
Now You Can Explore Mayan Temples in Assassin’s Creed Pirates’ Newest Update Posted by Jessica Fisher on December 23rd, 2014 [ permalink ] | Read more »
Soft Design aims to do free-to-play righ...
They say a team is only as big as its fans and that’s also certainly the case with video games, judging from the sales certain AAA ‘heavyweights’ get year-after-year. Soft Design took that principle as a core design philosophy and worked closely... | Read more »
Bogga Christmas Tree
Bogga Christmas Tree By Amy Solomon on December 23rd, 2014 Our Rating: Universal App - Designed for iPhone and iPad Bogga Christmas Tree allows young children to trim a tree, any time or place.   | Read more »
Opera Coast 4.0 Launches on iOS with 4 N...
Opera Coast 4.0 Launches on iOS with 4 New Features Posted by Jessica Fisher on December 23rd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Cricket Kids: Christmas Presents
Cricket Kids: Christmas Presents By Amy Solomon on December 23rd, 2014 Our Rating: Universal App - Designed for iPhone and iPad Cricket Kids: Christmas Presents allows children to play with digital toys opened for the Christmas... | Read more »
Lara Croft & Tomb Raider Mobile Bund...
Lara Croft & Tomb Raider Mobile Bundle – Only $4.99 Posted by Jessica Fisher on December 23rd, 2014 [ permalink ] Lara Croft is coming to you in | Read more »
SimCity BuildIt Review
SimCity BuildIt Review By Nadia Oxford on December 23rd, 2014 Our Rating: :: BUILDING AN OK TOMORROWUniversal App - Designed for iPhone and iPad SimCity BuildIt is a competent city-building game, but its free-to-play trappings are... | Read more »
SimCity Buildit – Tips, Tricks, and Stra...
Hello, Budding Mayors Want to know what we made of all this upgrading and inevitable waiting? Check out our SimCity BuildIt review! SimCity BuildIt is a city-building game from EA. Your job as mayor is to build houses for people to live in, industry... | Read more »

Price Scanner via MacPrices.net

Sony Fixing To Launch Large-Screen Android Ta...
Digitimes’ Aaron Lee and Joseph Tsai report that Sony, which last February exited the laptop computer market with the sale of its VIAO PC-making unit to a group of JApanese investors, is now expected... Read more
After Christmas sale: 13-inch Retina MacBook...
B&H Photo has new 13″ MacBook Pros on sale for up to $150 off MSRP as part of their Holiday pricing. Shipping is free, and B&H charges NY sales tax only: - 13″ 2.5GHz MacBook Pro: $1043 save... Read more
After Christmas sale: 15-inch Retina MacBook...
Adorama has 15″ Retina MacBook Pros on sale for up to $150 off MSRP. Shipping is free, and Adorama charges NY & NJ sales tax only: - 15″ 2.2GHz Retina MacBook Pro: $1899 save $100 - 15″ 2.5GHz... Read more
After Christmas sale: MacBook Airs for up to...
B&H Photo has 2014 MacBook Airs on sale for up to $120 off MSRP, for a limited time, for the Thanksgiving/Christmas Holiday shopping season. Shipping is free, and B&H charges NY sales tax... Read more
Apple now offering Certified Refurbished Mac...
The Apple Store is now offering Apple Certified Refurbished 2014 Mac minis, with models available starting at $419. Apple’s one-year warranty is included with each mini, and shipping is free: - 1.... Read more
Will Apple Build An A-series ARM Processor Po...
In computer terms, it’s been a very long time since the MacBook Air had a major redesign. More than four years have elapsed since Apple recast what had originally been more a pricy boutique device... Read more
iPhone 6s mini With Four-Inch Screen Rumored...
The Times of India’s Komal Mohan, citing a story in The Electronic Times of Taiwan, says that unnamed upstream supply chain sources report that Apple is gearing up to launch a new 4-inch screen... Read more
What’s The Current Value Of Your iOS Apps?
Basel, Switzerland based ConIT AG has announced AppZapp Notify and its free PC and Mac tool available for download. What is the present value of all my downloaded Apps? With AppZapp Notify, for the... Read more
PhatWare Releases WritePad Pro Advanced iOS W...
PhatWare Corporation has announced immediate availability of WritePad Pro 2.0, its advanced word processing, note-taking, and document management app which also takes full advantage of PhatWare’s... Read more
Last minute gift idea: Send an Apple Store Gi...
Send an Apple Store Gift Card by email this season, perhaps as a last minute Christmas gift. According to Apple, “Apple Store Gift Cards can be used to purchase Apple hardware and accessories at any... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Store Leader Program (US) - Apple, I...
…Summary Learn and grow as you explore the art of leadership at the Apple Store. You'll master our retail business inside and out through training, hands-on experience, Read more
Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.