Let u
be the upper number (in your example: 100) and l
be the lower number (example: 1), so you want to transform the interval/range/... [1, 100]
to a shrinked one.
With usual math knowledge one sees that removing some percent from the bottom/top is the same as just moving that number, so in your case you would want to use the interval [l * 0.25, u * 0.9]
instead of [l, u]
. This generalizes to all other values of course.
In case you don't want rational numbers but only integers, you'll have to think about whether you want to shrink more or less than 25/10% because you can't be exact then.
Using this new interval now you can create that function using pseudocode:
def transform(n, lower, upper):
interval = [lower * 0.25, upper * 0.9]
if n in interval:
return n
else if n < lower * 0.25:
return lower * 0.25
else if n > upper * 0.9:
return upper * 0.9