Home > .NET, Extreme Programming, Fun > Code Challenge Results

Code Challenge Results

Thank you to all to those that submitted code solutions. We will be running another code contest in a few weeks. Check back soon to enter our next contest. Congratulations to our contest winner: Rob Howarth

See the bottom of this page for an example solution

Others who submitted correct solutions

  • Rob Howarth
  • Scott Monnig
  • Eric Haddan
  • Thomas Eyde
  • Imran Baloch
  • Marc Chu
  • Cesar Neves
  • Jaider Ariza
  • Kenneth Hall
  • Teymur Mammadov
  • Cam Luc
  • Peter Burrell
  • Anthony Clayton
  • Mark Lindell
  • Steve Smith
  • Chris McKenzie
  • Amit Parikh
  • David White
  • Ron Warholic
  • Josh Clark
  • James Baker
  • Richard Deeming
  • Erik Jõgi
  • MORRIS CRISTOPHER
  • Scott Holodak
  • James Curran
  • Marius Ene
  • Matt Crouse
  • Michel Grootjans
  • Daniel Griffie
  • Xiu
  • Mordechai Sandhaus
  • Stuart Cam
  • Raj Rao
  • Rafik Ramtoolah
  • Ali Derman
  • Eric King

Sample Solution

        public class Converter
        {
                public string Convert(int number)
                {
                        StringBuilder buffer = new StringBuilder();
                        int quotient = number;
                        int remainder = -1;
                        while (quotient != 0)
                        {
                                remainder = quotient % BaseNumber;
                                quotient = quotient / BaseNumber;
                                buffer.Insert(0, ConvertSingleBaseNumber(remainder));
                        }
                        return buffer.ToString();
                }

                protected virtual string ValidCharacters
                {
                        get { return "0123456789xyz"; }
                }
               
                private string ConvertSingleBaseNumber(int remainder)
                {
                        return ValidCharacters[remainder].ToString();
                }
               
                private int BaseNumber
                {
                        get
                        {
                                return ValidCharacters.Length;
                        }      
                }
        }

        public class BinaryConverter : Converter
        {
                protected override string ValidCharacters
                {
                        get
                        {
                                return "01";
                        }
                }
        }

        public class OctalConverter : Converter
        {
                protected override string ValidCharacters
                {
                        get
                        {
                                return "01234567";
                        }
                }
        }

        public class HexConverter : Converter
        {
                protected override string ValidCharacters
                {
                        get
                        {
                                return "0123456789abcdef";
                        }
                }
        }

Did you like this challenge? Maybe you found it easy? Were always looking for talented people to join our growing team. Take a look at what we do at http://www.thycoticsolutions.com/careers.html If you feel you have what it takes to work at Thycotic – submit a cover letter, resume, and solution to this problem to tddjobs@thycotic.com

  1. Richard
    September 16, 2010 at 5:59 pm | #1

    Your sample solution fails with an IndexOutOfRangeException if you pass in a negative number.

    This is one of the biggest problems with TDD – your original tests didn’t include negative numbers, so your “correct” solution doesn’t allow for them.

    If your intention was to not handle negative numbers, you should either have used one of the unsigned integer types, or included a test to validate that a negative argument produced an ArgumentOutOfRange exception.

  2. September 16, 2010 at 9:16 pm | #2

    Richard,

    Yes – our sample also doesn’t handle zero. You make good points although I am not sure it is a problem with TDD – just sounds like unclear requirements.

    We deliberately leave those tests out (we actually ran them when reviewing solutions) to see if people think of them and it also makes the problem shorter to explain.

    Thanks for your feedback!

    Note that our sample solution is not meant to be the *definitive answer* – I am sure there are better solutions (some of the submissions were very interesting). It is meant to be a reasonable answer to the problem though.

  3. September 17, 2010 at 7:08 am | #3

    This seems to be approximately same solution that I had posted to you.

    May be some of you just change my sample. Please don’t be angry I am just guessing what comes in mind.

    By the way I agree that you are all genius programmers.

  4. October 17, 2010 at 10:38 am | #4

    I definitely like the way you handle the valid characters using a string/array is an elegant solution that I didn’t think of.

    The Converter is a concrete class that uses the thirteen base as default. That’s something I not very comfortable with.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: