Andrew Channels Dexter Pinion

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

October 15, 2003

Kata 2, Pass 1

Now I've skipped to Kata 2. My first pass is a fairly standard, procedural, binary search;

def chop(item, collection):
    start=0
    end=len(collection)-1

    while ( start <= end ):
        middle=(start+end)/2
        if item==collection[middle]:
            return middle
        elif item < collection[middle]:
            end = middle-1
        else:
            start = middle+1
    return -1

For my next exercise I'm going to try either a recursive solution or something with generators. I'm just hoping it will take slightly less than the two hours it took me to come up with this one.

Posted by Andy Todd at October 15, 2003 09:45 PM

Comments