def scale(x, length):
    """
    Scale points in 'x', such that distance between
    max(x) and min(x) equals to 'length'. min(x)
    will be moved to 0.
    """
    s = float(length - 1) / \
        (max(x) - min(x)) if x and max(x) - min(x) != 0 else length
    return [int((i - min(x)) * s) for i in x]