Wednesday, 23 May 2012

Combine() (or Collapse) DateRanges - WINNER

The winning code for the combine competition is shown below:



Feedback and improvements: 

During the course of the competition we made some changes to the libraries.
Changed the Combine() method to Collapse().
In the DateRange class the Overlap() method was changed to GetOverlap() and a new Overlaps() method was created, which returns a boolean.

Improvements on the winning code are only minor:
- Added a null check at the start
- Changed the code to use the new Overlaps() method

Possible Improvements:
- Would be great if there was a way of only traversing the collection of tasks once (after it has been sorted).
(There is a way.... We are leaving a $50 US for the next 2 people who can traverse the collection once and still get the same result.)


11 comments:

  1. I've improved upon this solution, traversing the collection only once. How do I go about claiming my $100 reward?

    ReplyDelete
  2. Great. Did you get it to pass all the unit tests? (You can download the files from the "Combine() (or Collapse) DateRanges" competition page, there are also 2 secret tests that it needs to pass.)

    If your code passes all the unit tests then please send us your vWorker username via the "Contact Us" page.
    We will create a private project on vWorker and invite you to it. You can then upload your code for us to double check. If you are correct, we will credit your account with $100 US. (We will make sure you receive $100 US after paying vWorker their commission.)

    ReplyDelete
  3. Well, my improvement has been accepted, so I guess it's just a matter of time. :>

    ReplyDelete
  4. @Egor: Yes there is a solution, but won't make the solution available just yet so others can have a try. Reduced the prize money to $50.

    ReplyDelete
    Replies
    1. So it's a real 1-time traversal, no loops hidden within LINQ, no loops hidden via recursion, etc.?

      Delete
    2. @Egor: Yes, it is definitely a 1-time traversal, with no hidden loops or recursion etc... I am sure you can get it, but you might have to think of the problem a little differently.

      Delete
    3. @orc: And no modification of the data looped through inside the loop? :)

      Delete
    4. Sent a possible solution via 'Contact Us' form.

      Delete
  5. Thanks Egor... well done! Sending you a bonus now...

    ReplyDelete
  6. why not put the timeEvents in inner loop? it's already sorted, put it to inner loop will improve performance(of course an algorithm is needed for searching on timeEvents).

    ReplyDelete