1. Computing & Technology

Discuss in my forum

Programming Contest 38 - Fighting Fires

Deadline August 31 2010

By , About.com Guide

Challenge 38 Fighting Fires Image

In this programming contest you are given a map of the countryside in a 12 x 12 block. It's made up of open squares (.), trees (A), Houses (H), river (r) and roads( = or /). If there is a fire in the location then it's set to F (burnt!)

Unfortunately at a random places on the map (use 3,3 to test), some thoughtless individual has improperly put out a fire and being hot, the fire quickly spreads. As fire chief you get to make woo woo sounds and decide where to blow up a fire break to try and save as many houses as possible. Well your App does.

Before the 10 rounds your App must spread the initial fire once according to the rules below. There are then 10 rounds. At the start of each round your App must pick a a square to blow up (It sets it to B). Then it must spread the fire according to these simple rules.

  • Build a list of Squares on fire.
  • Set every square in that list to 'X'.
  • Go through the list and set every one of the 8 squares around a fire location to F, on fire if it is flammable.
  • Only A and H squares are flammable so you can only blow them up (Set them to B).

Your App may be able to contain the fire and put it out or maybe not. After ten rounds, count up how many H are left and output it, together with a character dump of the map (like the original only with your 10 blows up locations and fire damaged squares).

Input File

Use this 12x12 character.

....rA..AA.A
.H.AArAAAHA.
.AAAArA=====
H.A.AA=HHH..
.HAA==rA.AAH
..A/AArA.AA.
===A.AArAA.H
.AAA^..rAAA.
.AA^^^HrAHAH
.AH^^H.ArAA.
.A.AAAArrAA.
.......rr.A.

Highest number of H left at the end wins. Note the same initial fire location will be used for all entrants.

Final Results

There were three entrants, James Borden from Japan, Matthew DeKray and Shawn Knight both from the USA. Of the three James, managed to run successfully and saved 11 houses - so congratulations to James. Matthew's very nicely presented WPF entry was manually operated so didn't quite achieve a result and Shawn's unfortunately started correctly and corrupted the map. Congrats to James!

If Matthew or Shawn could amend their programs, I'll rerun them.

  • James Borden 11 houses - C# Website
  • Matthew DeKrey Didn't output - C# Website
  • Shawn Knight Map corrupted - C++
  • Rules

    This is for glory only. About.com does not permit prizes to be given.

    Please submit your source code and the output file to the cplus.guide@about.com?subject=Programming Contest 38 email address with the subject line Programming Contest 38.

    It must compile with Open Watcom, Microsoft Visual C++ 2005/2008/2010 Express Edition/Microsoft Visual Studio 2003/2005/2008 or Borland Turbo C++ Explorer, Microsoft Visual C# 2005/2008/2010 Express Edition or GCC/G++. If it doesn't compile, it can't be run so is automatically disqualified.

    Please include your name, age (optional), blog/website url (optional) and country. Your email address will not be kept, used or displayed except to acknowledge your challenge entry. You can submit as many entries as you like before the deadline which is August 31 2010.

    The top ten entries will be listed, judged purely on points. A condition of entry is that you allow your source code to be published on this website, with full credits to you as the author.

    ©2012 About.com. All rights reserved.

    A part of The New York Times Company.