def circling_inwards_up(l): '''Motion towards center. 1. elements from greatest absolute value from center to least 2. down before up in case of equal absolute value from center ''' assert sequencetools.is_unique(l) mean = sequencetools.arithmetic_mean(l) distances = [abs(mean - x) for x in l] pairs = zip(distances, l) def helper(pair_1, pair_2): if pair_1[0] < pair_2[0]: return -1 elif pair_1[0] > pair_2[0]: return 1 elif pair_1[0] == pair_2[0]: ## only line that differs from twin return -cmp(pair_1[1], pair_2[1]) pairs.sort(helper) result = [x[1] for x in pairs] return result
def outwards_up_down_center(l): '''Motion away from center. 1. upper half ascending 2. lower half descending 3. center element if present ''' assert sequencetools.is_unique(l) lower = _get_lower_half(l) upper = _get_upper_half(l) center = _get_center_value(l) lower = list(reversed(sorted(lower))) upper = list(sorted(upper)) return upper + lower + center
def undulate_up_down(l, repetitions = 1): '''Wavelike motion up then down. 1. all elements, including greatest, ascending 2. all elements, excluding greatest, descending Elements do not repeat at peaks and troughs. ''' assert sequencetools.is_unique(l) and sequencetools.is_numeric(l) ascending = list(sorted(l)) descending = list(sorted(reversed(l))) descending = descending[1:-1] period = ascending + descending least = [min(l)] result = period * repetitions + least return result
def undulate_down_up(l, repetitions = 1): '''Wavelike motion down then up. 1. all elements, including least, descending 2. all elements, excluding least, ascending Maximum and minimum elements are not repeated at peaks and troughs. ''' assert sequencetools.is_unique(l) and sequencetools.is_numeric(l) descending = list(sorted(reversed(l))) ascending = list(sorted(l)) ascending = ascending[1:-1] period = descending + ascending greatest = [max(l)] result = period * repetitions + greatest return result
def up(l): assert sequencetools.is_unique(l) result = list(sorted(l)) return result
def down(l): assert sequencetools.is_unique(l) result = list(reversed(sorted(l))) return result