def scale(score, omax, omin, smax, smin):
    """
    >>> scale(2871, 4871, 0, 1000, 0)
    589
    """
    try:
        return ((smax - smin) * (score - omin) / (omax - omin)) + smin
    except ZeroDivisionError:
        return 0