解決策は簡単です:
- 最小のアイテムと最大のアイテムを選び、違いを見つけます。
- (最大項目 - 最小項目) は (最大 - 最小) にマップされます。
- コンピューティング
ratio = (max-min)/(largest_item-smallest_item)
final_value = min_value + ratio*(value-smallest_item)
数学関数として:
f(x,max,min,largest,smallest) = min + (max-min)/(largest-smallest)*(x-smallest)
where:
x : Input item's price
max: Maximum value (here, 110)
min: Minimum value (here, 55)
largest: Largest item in input (Here, 1081)
smallest: Smallest item in input (Here, 49)
@amitが正しく指摘しているように、1つのチェック:最大アイテムと最小アイテムが異なることを確認してください。
x = 93 としましょう。他に 4 つの値があります。
f(x,max,min,largest,smallest) = min + (max-min)/(largest-smallest)*(x-smallest)
value = 55 + ((110-55)/(1081-49)) * (93-49)
value = 57.344961
さらに遠く、
f(93,110,55,1081,49) = 57.344961
f(49,110,55,1081,49) = 55
f(1081,110,55,1081,49) = 110