A little visualization goes a long way

Posted by: Clarity Blogs: ASP.NET, on 16 Apr 2009 | View original | Bookmarked: 0 time(s)

Clarity recently held its 15th Tech Challenge (TC). TCs are recurring coding competitions amongst the consultants here. Oftentimes the problems are released weeks in advance, such as developing an AI for a card game, and at the deadline the various solutions are tested against each other. TC 15 was the third time that weve done a Top Coder style tech challenge, where we compete to solve as many short coding problems in 90 minutes as possible.

I like this type of TC because it requires virtually no prep time to compete in (maybe some prep time to win) and it gives me a chance to work on some pure logic puzzles, the likes of which I dont see every day during client work. I had a respectable finish, but was a little upset over one of the problems I missed.

The problem was an easy one, but in my rush to get through as many problems as possible, I made a mental modeling mistake. The problem statement was:

Southern China is suffering from a heavily snowy winter. The heavy snow even causes the closure of an important highway connecting southern and northern China. You've got several reports containing the start and end points of highway segments covered by heavy snow. Given those reports as two int[]s startPoints and endPoints, you are to return the total length of highway segments covered by snow. Note that the reported segments may overlap.

Some further constraints were given, basically allowing me to dispense with any error handling and then some test examples were given:

Example 1: {17,85,57}; {33,86,84}

Returns: 44 (these segments don't overlap)

 

Example 2: {45,100,125,10,15,35,30,9}; {46,200,175,20,25,45,40,10}

Returns: 132 (There are 3 segments covered by snow: 9-25, 30-46 and 100-200)

<-- and so on -->

My solution was able to pass all the given test cases, except for the first one. I ran out of time before I fixed it, but it turns out my overlap code was a bit off, and in the first example I was counting the segment between 84 and 85 as being snowy, when it was actually a gap.

Beyond a dish of humble pie for myself, the reason to bring this up was that it got me thinking about how much graphical visualizations can help to model a problem. For example, I am pretty sure I would have gotten this problem right on the first try if the examples had looked a bit more like this:

road_clear

road_simple

road_overlap

road_gap

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: Software | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 922 | Hits: 12

Similar Posts

  • 7 Stages of new language keyword grief more
  • Goodbye mocks, Farewell stubs more
  • Levels of Enthusiasm more
  • A Look back at the History of .NET Interop more
  • Work on your Vocabulary. The word for today is "CodableValue" more
  • FormVarsToObject - a quick way to collect form input values more
  • How long before ALT.NET becomes NOT.NET? more
  • Zen of the Web Programming Model (part 2) more
  • What do I actually do...? more
  • FogBugz 6 Recognizes Estimates And Actuals Are Not Bounded Evenly On Both Sides more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD