1. Computing & Technology

Discuss in my forum

David Bolton

Programming Challenge 27 Published

By , About.com GuideAugust 31, 2009

Follow me on:

Challenge 26 will be marked on Wednesday evening so there's still time to get your entry in. There's just one so far.

Challenge 27 is a simple but different programming exercise. On a game map (made up of a 2d array of characters representing land, sea, forest and mountains), your application must add as many cities as possible. However these cities must be placed only on land (not in forests or mountains or sea!) and some cities must be near the sea. No cities should be too near each other. That's it, get as many as possible on the map. The deadline for this is the end of September.

Comments
September 1, 2009 at 10:19 am
(1) Laci :

“No cities should be too near each other.”
So if I assume that right next to each other is not “too near”, it’s alright? [Or how should I interpret that? How much space should there be? Some euclidean distance? Manhattan?]

September 1, 2009 at 1:35 pm
(2) David :

How about “No two cities can be within 7 locations (as the crow flies) of each other.” and The “as the crow flies” distance restriction simply means that if city 1 is at point x1,y1 and city 2 at x2,y2 then sqr root((x2-x1)2 + (y2-y1)2) must be > 7. It’s simple Pythagoras theorem.

So if one city was at 10,10 and the other at 11,11 ie they are next to each other but the distance = sqrt(2) ie around 1.4 which is much less than 7 so not allowed.

It’s all in the Programming Challenge 27 page.

David
About C, C++ and C# Guide

September 1, 2009 at 2:00 pm
(3) Edgar :

If I read the instructions correctly, there is no functional difference between mountains and forest. Am I missing anything?

Can you tell us more about how the entries will be judged? I assume they will be tested against a variety of maps. Will each entry’s “score” just be the average number of cities it places across all maps? Is speed only relevant in the event of an exact tie in the number of cities placed?

September 1, 2009 at 4:37 pm
(4) edgar :

Also, when you say “The first 15 cities put on the map must be placed by the sea. I.e. on land, next to a ~”, what do you mean? Does each piece of land have four neighbors (N, S, E, W) or 8 neighbors (N, S, E, W, NW, SW, NE, SE)?

September 2, 2009 at 2:57 pm
(5) cplus :

Edgar, good points thanks! I’ll update the challenge document. Yes there is no difference between forest and mountain and if any of the 8 squares around a location have sea then it’s considered sea-side.

September 2, 2009 at 5:06 pm
(6) MakisCE :

seems like a well-specified and interesting challenge..
another question David:
Will you test the entries with the supplied test.txt file, or with another unknown one?

September 2, 2009 at 11:38 pm
(7) Jon :

“Just in case there is a tie, please include timing code with loops so it takes 1-10 seconds. If if you code ran once in 20 ms then doing it a hundred times would take 2 seconds.”

I’m just a little confused as to what you mean by this… Do you mean to say we should report timing at each loop or enclose the entire code to keep track of time over multiple passes of the program. Thanks! (apologies if I’m just missing something)

September 3, 2009 at 3:07 pm
(8) David :

Makis. Congrats on winning Challenge 26, I’ll publish the results shortly!

It shouldn’t matter if I use another file should it? It would be identical- same number of lines and chars per line. Would that cause problems?

Jon, some entries have been so fast I’ve had to run it in a loop hundreds or thousands of times so the overall timing was reasonably measurable.

So put the whole code inside a repeat loop and time the total time. Divide the total time by loop count to give an accurate time for one loop.

David
About C, C++ and C#

September 4, 2009 at 6:07 pm
(9) Pedro :

I’m having fun!
… 12 random cities

http://i32.tinypic.com/11lklkp.png

September 5, 2009 at 2:40 pm
(10) Pedro :

49 random cities (the first 15 by the sea) in 0.08 secs.

http://i32.tinypic.com/wvu5nc.gif

September 6, 2009 at 5:53 pm
(11) MakisCE :

Pedro, that 0.08 secs time is suspicious :)
do you count from start (read file) to finish,
or just the time placing cities?

September 10, 2009 at 5:08 am
(12) Pedro :

I “lost” the source file — but I’m sure the timing included everything except the malloc/free calls. My current version (with backups!) is not yet functional.

September 23, 2009 at 1:28 pm
(13) Adam :

Are people still working on this? Mine runs a lot longer than Pedro’s but is able to deploy a lot more.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>
Related Searches programming challenge

©2012 About.com. All rights reserved.

A part of The New York Times Company.