Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

October 16, 2003

Kata 2, Revisited

Reviewing the definition of Kata Two I'm a little unsure what constitutes another algorithm. Is another search algorithm allowable, or should I implement another flavour of the binary chop?

All the specification states is that the code has to pass the unit tests. If this is the case then my second submission (in Python, naturally) is;

def chop(item, collection):
    for index, element in enumerate(collection):
        if item==element:
            return index
    return -1

It will work, but I make no claims about efficiency. Oh, and you will need at least Python 2.3, because that is the first version that included the enumerate function.

Posted by Andy Todd at October 16, 2003 10:23 AM


"This Kata is straightforward. Implement a binary search routine (using the specification below) in the language and technique of your choice. Tomorrow, implement it again, using a totally different technique. Do the same the next day, until you have five totally unique implementations of a binary chop."

Nope, you have to use a binary chop for all five solutions.

No, I can't think of five different ways of doing this either. ;-)

Posted by: Simon Brunning on November 13, 2003 04:53 PM