All pastes #2089242 Raw Edit

Something

public text v1 · immutable
#2089242 ·published 2011-10-12 04:22 UTC
rendered paste body
def successor(base,predecessor,k):
    i=k-1
    while True:
        #find out if the sequence is going up or down
        direction = 1
        for j in xrange(0,i):
            #first is always ascending
            if predecessor[j]%2 == 1:
                direction *= -1;
        #check boundaries
        if (direction==1 and predecessor[i]==base[i]-1) or (direction==-1 and predecessor[i]==0):
            i-=1
            continue
        elif direction==1:
            predecessor[i]+=1
            break
        elif direction==-1:
            predecessor[i]-=1
            break
    return predecessor