MacTech Network:   MacTech Forums  |  MacForge.net  |  Computer Memory  |  Register Domains  |  Cables  |  iPod Deals  | Mac Deals  | Mac Book Shelf


  MacTech Magazine

The journal of Macintosh technology

 
 

Magazine In Print
  About MacTech  
  Home Page  
  Subscribe  
  Archives DVD  
  Submit News  
  MacTech Forums  
  Get a copy of MacTech RISK FREE  
MacTech Only Search:
Community Search:
MacTech Central
  by Category  
  by Company  
  by Product  
MacTech News
  MacTech News  
  Previous News  
  MacTech RSS  
Article Archives
  Show Indices  
  by Volume  
  by Author  
  Source Code FTP  
Inside MacTech
  Writer's Kit  
  Editorial Staff  
  Editorial Calendar  
  Back Issues  
  Advertising  
Contact Us
  Customer Service  
  MacTech Store  
  Legal/Disclaimers  
  Webmaster Feedback  
 Get Netflix

 October 2002 Programmer's Challenge

Area

Mail solutions to: progchallenge@mactech.com

Due Date: 11:59pm ET, Saturday, 12 October 2002


As those of you who are regular readers know, the Programmer�s Challenge problems have become more difficult over time. Just as all scientific discoveries worth making had been made by the mid-twentieth century, so it is that all simple Challenge problems have been posed and solved by this time.  Then again, as they say, maybe not.  This month's problem is borrowed from http://www.polymathlove.com/, where Gary Smith posts software he uses in teaching mathematics to elementary and middle school students. One of his programs is called Area Puzzles, where students create rectangles with specified areas to cover a grid subject to certain constraints.

The prototype for the code you should write is:

 

void Area(

  const short *cells,

     /* rectangle to be covered with smaller rectangles */

     /* index [row][col] as cells[row*rectWidth + col[ */

     /* value N>0 means this cell must be covered by a rectangle of area N */

  short rectWidth,

  short rectHeight,

  Rect yourRects[]

);

 

Your Area routine will be called with a rectangle of cells of width rectWidth and height rectHeight. Your task is to create a set of smaller rectangles (yourRect) that cover these cells. In doing so, you need to satisfy some constraints. Certain of the cells will have a nonzero value, and those cells must be covered by a rectangle with an area equal to that value.  As an example, if the input cells were configured as follows �

 

  0 0  3  0 6  0  0 0  0  8

  0 6  0  0 0  0  0 0  0  0

  0 0  0  0 0  0  4 0  0  0

  0 0  3  0 0  0  0 0  0  0

  0 0  0  0 0  0  0 0  0  0

  6 0  0  0 0  0  0 0 15  0

  0 0  0  0 0  0  0 0  0  0

  0 10  0  0 24  0 0  4  0 0

  0 0  0  0 0  0  0 0  0  0

  0 0  0  4 0  0  4 0  0  3

 

... you might create a set of rectangles like this, where each cell is shown with the number of the rectangle including that cell.

 

  1  1 1  2  2 2  3  3 3  3

  4  4 5  2  2 2  3  3 3  3

  4  4 5  6  6 6  6  7 7  7

  4  4 5  8  8 8  8  7 7  7

  9 10 10  8 8  8  8 7  7  7

  9 10 10  8 8  8  8 7  7  7

  9 10 10  8 8  8  8 7  7  7

  9 10 10  8 8  8  8 13 13 14

  9 10 10  8 8  8  8 13 13 14

  9 11 11 11 11 12 12 12 12 14

 

You should return the rectangles that cover the cell array and satisfy the constraints as yourRects. Each cell may be included in only one rectangle. If the cell has a nonzero value when Area is called, it must be included in a rectangle with an area equal to that value. Memory for the rectangles you create will be allocated for you, and there will be as many of those rectangles as there are nonzero values in the cells array. Any solution that covers the entire cells array and satisfies the constraints will be considered correct.

Scoring will be based on execution time - the winner will be the solution that correctly solves the puzzles with the smallest execution time.

This will be a native PowerPC Carbon C++ Challenge, using the Metrowerks CodeWarrior Pro 7.0 development environment. Please be certain that your code is carbonized, as I may evaluate this Challenge using Mac OS X. Also, when submitting you solution, please include the project file and the code you used to test your solution. Occasionally I receive a solution that will not compile and, while I always try to correct these problems, it is easier to do so if I have your entire project available.


Test code for this Challenge is available.


You can get a head start on the Challenge by reading the Programmer's Challenge mailing list. It will be posted to the list on or before the 15th of the preceding month. To join, send an email to listserv@listmail.xplain.com with the subject "subscribe challenge-A". You can also join the discussion list by sending a message with the subject "subscribe challenge-D".





Generate a short URL for this page:


Click on the cover to
see this month's issue!

TRIAL SUBSCRIPTION
Get a RISK-FREE subscription to the only technical Mac magazine!

Today's Deal


Apple Special

Order
Snow Leopard,
Mac Box Set, Family Pack,
and Snow Leopard Server
at a discount.
 


MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797

Register Low Cost (ok dirt cheap!) Domain Names in the MacTech Domain Store. As low as $1.99!
Save on long distance * Upgrade your Computer. See local info about Westlake Village
appleexpo.com | bathjot.com | bathroomjot.com | bettersupplies.com | comclothing.com | computerlunatics.com | dotcomclothing.com | explainit.com | exposinternational.com | homeismycastle.com | hoodcards.com | intlexpo.com | keyinfocard.com | kosheru.com | learnmorsels.com | localdealcards.com | lvschools.com | macjobsearch.com | mactechjobs.com | mactechmonitor.com | mactechsupplies.com | macwishbook.com | movie-depot.com | netprofessional.com | nibblelearning.com | notesintheshower.com | officejot.com | onlinebigbox.com | palmosdepot.com | peopleslineitemveto.com | showerjot.com | snapestore.com | snapishop.com | snapistore.com | snaptradingpost.com | stimulusmap.com | stimulusroadmap.com | triunfoguides.com | video-depot.com
Staff Site Links



All contents are Copyright 1984-2008 by Xplain Corporation. All rights reserved.

MacTech is a registered trademark of Xplain Corporation. Xplain, Video Depot, Movie Depot, Palm OS Depot, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, NetProLive, JavaTech, WebTech, BeTech, LinuxTech, Apple Expo, MacTech Central and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.