<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def rgb_reduce(r, g, b, mode=8):
    '''
    Convert an RGB colour to 8 or 16 colour ANSI graphics.
    '''
    colours = ANSI_COLOURS[:mode]
    matches = [(rgb_distance(c, map(int, [r, g, b])), i)
        for i, c in enumerate(colours)]
    matches.sort()
    return sequence('m')(str(30 + matches[0][1]))