The file consists of 50 lines of text. Each line consists of 3 sections: First is 3 characters made up of spaces and digits that you can ignore, then 80 characters which are either a space or a + then another 2 characters. The first 3 and last 2 characters are just 1 or 2 digits line numbers padded with spaces. The important part is the 80 characters.
I.e. it will look something like this (the first line <3> etc is not part of the file).
<3><-------------------------------------------80--This is a map of a game world where each location is either land or sea. Land points are +, sea are spaces. What you have to do is process the 80 x 50 map, determine how many continents there are and output how many continents there are plus a list of those continents, together with the size of each continent. The definition of a continent is one or more connected locations where each location is a +. Connected means that in a 3 x 3 grid around a +, if any of the 8 surrounding locations contains a + then the two are connected.
--------------------------------------><2>
File starts here:
1 1
27 ++++++++ ++++ +++++++ ++++++++++++ +++ 27
28 ++++++++ ++++ +++++++ ++++++++++++ + ++++ ++++++ 28
+The 4 locations + are next to each other.
++
+
Download the text file.
For example your output should look something like this:
There are 5 Continents
Continent 1 has 208 +.
Continent 2 has ...
Note - The actual number of continents may be more or less than 5-that example just shows what output might look like.
You can enter in C, C++ or C#. Please add timing code to your entry to save me quite a big job! This is mandatory! as it takes way too long for me to add timing code in. The routines to do this are in the How to Sections below.
This is for timing on Windows, if you have similar code for Linux or Mac, please send it to me and I'll be happy to publish it.Results
Thanks to everyone who entered and congrats to Faisal. The links for the ten fastest either show the source code or download a zip file if there is more than one file.Name Language (Age,Country) Time
- Faisal Yousuf C++ 0.0003343
- Dongfang Xie C (38,Canada) 0.000409
- Philippe Boucher C++ (32) 0.000415
- Andre Prata C (19,Portugal) 0.00106
- Siddharth Hegde C++ 0.0016405
- g.v.Vidhya C (India) 0.00176
- Rodrigo Paniagua C (27, Spain) 0.00176
- Neil McCoy C++ (Australia) 0.0021464
- Yatin Salian C++ (27,India) 0.00255
- Peter Adamko C# (40,Slovakia) 0.0030043
- Bobby Boyle C++ (23,Canada) 0.00388
- Sundara Raman C++ (19,India) 0.004107
- Michael Hitt C++ (USA) 0.005883
- Michael van der Wal C# (43,The Netherlands) 0.0213939
- Siridiion Cabudian C++ 0.049395
- Pranav Prakash C++ (22,India) N/A
- Barry Hadder C N/A
- Turcu Septimu C (Romania) N/A
- Bobby J Knight C++ (25,USA) N/A
More Programming Challenges
- Link to Rock, Scissors and Paper Bot Ongoing Programming Challenge - Runs weekly until 2008.
- Link to Programming Challenge 1 - Find the 100,000th number (Finished)
- Link to Programming Challenge 3 - Manage Elevators. (Finished)
- Link to Programming Challenge 4 - Guess the Mastermind code (Deadline September 30 2007)

