Ejemplo n.º 1
0
def _reversal_sort_log(d, p):
    '''Print a shortest path log from the identity permutation to the permutation p.'''
    d_rev, start, stop = d[p]
    print d_rev  
    print start + 1, stop
    for _ in xrange(d_rev - 1):
        p = rr.reverse(p, (start, stop))
        _, start, stop = d[p]
        print start + 1, stop
Ejemplo n.º 2
0
def all_reverses_with_moves(p):
    '''A generator of all possible reverses of a permutation p.'''
    n = len(p)
    return ((rr.reverse(p, (j, k)), (j, k)) for j in xrange(n - 1) for k in xrange(j + 2, n + 1))