## 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):
self.store = 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.store[self.index(k)] = o

def __iter__(self):
for k in range(self.length):
yield self.store[self.index(k)]

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)))