I'm trying to program something but the math has me stuck...
I am using the below algorithm to find how large a number is compared to others. It outputs a score between 0 and 1; with 0 always being the lowest number in the range, 1 the highest in the range, and 0.5 in the middle.
score = (number_being_scored - lowest) / (highest - lowest)
For example:
- number_range = 10, 63, 64 ,72, 17, 32, 28
- highest_number = 72
- lowest_number = 17
- number_being_scored = 63
score for number 63 = (63 - 17) / (72 - 17) = 0.84
For my scores I always need "1" to be "good" and "0" to be "bad".
So it works great when a higher number is desirable (e.g. comparing a range of speeds, the faster the better) because the highest number in the range will always score 1.
But now I need a calculation on that same scale (1=good, 0=bad) where the lowest number in a range is desirable (e.g. comparing prices, the lower the better).
So this time the lowest number in the range should always score 1 and the highest number should score 0.
There's probably a super simple solution but I can't see it.
One possible thing to do is consider:
$$1 - \frac{\text{number being scored - lowest}}{\text{highest - lowest}}$$