Example #1
0
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
Example #2
0
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