def map(x, in_min, in_max, out_min, out_max):
    """
    Map a value from one range to another

        :param in_min: minimum of input range
        :param in_max: maximum of input range
        :param out_min: minimum of output range
        :param out_max: maximum of output range

        :return: The value scaled to the new range
        :rtype: int
    """
    return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)