Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
5th solution in Creative category for Robot Sort by gyahun_dash
from itertools import chain
from operator import itemgetter as getter
def swapsort(rods):
enum = enumerate
indices = tuple(map(getter(0), sorted(enum(rods), key = getter(1))))
slides = (i - sum(k < i for k in indices[: j]) for j, i in enum(indices))
pops = chain(*(range(m + i, m, -1) for m, i in enum(slides)))
return ','.join('{}{}'.format(p - 1, p) for p in pops)
Aug. 15, 2014