No Exercise Today

May 20, 2016

I’ve been busy at work and haven’t had time to prepare an exercise for today. I apologize.

Your task is to solve a previous exercise that you haven’t yet solved. Have fun!

One Response to “No Exercise Today”

  1. Jussi Piitulainen said

    A take on that interleaved sorting exercise: a minimal way to see even and odd positions as collections of their own right, backed by the actual store that contains them both. (This is Python.)

    class See(object):
        def __init__(self, store, length, index):
   = store
            self.length = length
            self.index = index
        def __setitem__(self, x, vs):
            '''handle self[:] = vs when lengths match'''
            for k, o in enumerate(vs):
      [self.index(k)] = o
        def __iter__(self):
            for k in range(self.length):
    def demonstrate(data):
        every = See(data, len(data), lambda k: k)
        even = See(data, -(-len(data) // 2), lambda k: 2 * k)
        odd = See(data, len(data) // 2, lambda k: 2 * k + 1)
        print('before:', *map(''.join, (every, even, odd)))
        even[:] = sorted(even)
        odd[:] = sorted(odd, reverse = True)
        print('after:', *map(''.join, (every, even, odd)))
    # before: abracadabra arcdba baaar
    # after: arabbacadar aabcdr rbaaa
    # before: 0123456789 02468 13579
    # after: 0927456381 02468 97531

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

%d bloggers like this: